| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
买学问 - 大牛一对一辅导,有问必答买学问 - 专业的付费知识问答平台
共有 496 人关注过本帖
标题:恳请各位大佬帮忙看看代码出了什么问题
只看楼主 加入收藏
风从南方来
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2019-1-7
结帖率:0
  已结贴   问题点数:20  回复次数:5   
恳请各位大佬帮忙看看代码出了什么问题
C语言
DEV C++里跑是对的 放在OJ上就无输出结果

程序代码:
#include<stdio.h>
#include<string.h>

int datai=0;                                         //记录有多少组数据

struct DATA
{
    char TIME[15];
    char ID[12];
    char ROOM[15];
    char SAFTY[10];
    char ACTION[5];
};

int main()
{
    void input(struct DATA data[]);
    void person(struct DATA data[]);
    void date(struct DATA data[]);
    void place(struct DATA data[]);
    struct DATA data[30], * p = data;
    int n[5]={1},i=0,k=0;
    char program='9';
  /*  for( ; program !='0'; )              //重复获取program直到=0
    {
         
        scanf ("%c",&program);
        if(program!='0')                            //若program=0则不进行选择
        {  
            switch (program)                        //选择操作
            {
                case '1': input(p); break;       // 输入数据,获取数据组数
                case '2': person(p); break;  // 根据学号
                case '3': date(p); break;
                case '4': place(p); break;
            }
      }  
    }  */   

 /*********如果用switch OJ就会判time limit exceeded , 如果用下面的for OJ直接判wrong answer 输出为空*****************/
    for(;n[k]!=0;i++)
    {
       scanf("%d",&n[i]);
       getchar();
       if(n[i]==1) input(p);
       else if(n[i]==2) person(p);
       else if(n[i]==3) date(p);
       else if(n[i]==4) place(p);
       k=i;
    }                                   //循环检测,直至出现 0 ,结束程序
    return 0;
}


/*将门禁控制器传来的数据信息录入至数据库内*/
void input(struct DATA data[])
{
    int check=1;
    char com1[2]={'0'}, com2[2]={'\0'};
    
    for(;check!=0;datai ++)
    {
        scanf("%[^(,&&#)],%[^,],%[^,],%[^,],%[^;];",data[datai].TIME,data[datai].ID,data[datai].ROOM,
                                                    data[datai].SAFTY,data[datai].ACTION);
        getchar();                                    //避免\n录入(但是第一组数据避免不了?)
        strncpy(com1,data[datai].TIME,1);             //将输入的数据中第一个字符复制到com1中
        check=strcmp(com1,com2);                      //检查com1是否等于空
     /*   if(data[datai].TIME[0]=='\n')
        {
            data[datai].TIME[0]=data[datai].TIME[1];
            data[datai].TIME[1]=data[datai].TIME[2];
            data[datai].TIME[2]=data[datai].TIME[3];
            data[datai].TIME[3]=data[datai].TIME[4];
            data[datai].TIME[4]=data[datai].TIME[5];
            data[datai].TIME[5]=data[datai].TIME[6];
            data[datai].TIME[6]=data[datai].TIME[7];
            data[datai].TIME[7]=data[datai].TIME[8];
            data[datai].TIME[8]=data[datai].TIME[9];
            data[datai].TIME[9]=data[datai].TIME[10];
            data[datai].TIME[10]=data[datai].TIME[11];
            data[datai].TIME[11]=data[datai].TIME[12];
            data[datai].TIME[12]=data[datai].TIME[13];
            data[datai].TIME[13]='\0'; 
            
        } */
    }
    

    
    datai=datai-1;
}


/*查询某一同学相关的所有门禁数据,并全部列举出来。*/
void person(struct DATA data[])
{
    int i,j,check=1,count1=0,count2=0;
    char who[10][15]={'\0'};
    char com3[2]={'0'}, com4[2]={'#'};
    
    for(i=0;check!=0;i++)
    {
        scanf("%s",who[i]);                      //输入要查询的同学id
        strncpy(com3,who[i],1);
        check=strcmp(com3,com4);                 //同上
    }
    count1=i-1;                                  //获取一共多少名同学
    
    for(i=0;i<count1;i++,count2=0)
    {
        for(j=0;j!=datai;j++)                      //依次查每一位同学匹配的数据
        {
            check=strcmp(who[i],data[j].ID);     //若id匹配 则令check=0
            if(check==0)
            {
                printf("%s,%s,%s,%s,%s;\n",data[j].TIME,data[j].ID,data[j].ROOM,
                                           data[j].SAFTY,data[j].ACTION);
                count2++;                        //若有输出 则count2递加
            }
        }
        if(count2==0) printf("No record!\n");    //若count2没有递加,说明无匹配数据,输出no record
    }
}


/*查询某一时间段内所有实验室的门禁数据,并全部列举出来。*/
void date(struct DATA data[])
{
    int i, j, check1=1, check2=0;
    int count1=0, count2=0;
    
    int montha=0,monthb=0,month1=0;
    int monthc=0,monthd=0,month2=0;
    int daya=0,dayb=0,day1=0;
    int dayc=0,dayd=0,day2=0;
    int year[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    
    char when1[10][8]={'\0'}, when2[10][8]={'\0'};
    char com3='1';
    
    for(i=0;com3!='\0';i++)
    {
        scanf("%[^( &&#)] %[^\n]",when1[i],when2[i]);                      //输入要查询的TIME
        if(when1[i][0]=='\n')
        {
            when1[i][0]=when1[i][1];
            when1[i][1]=when1[i][2];
            when1[i][2]=when1[i][3];
            when1[i][3]=when1[i][4];
            when1[i][4]=when1[i][5];
            when1[i][5]=when1[i][6];
            when1[i][6]='\0';
        }
        com3=when1[i][0];
        
    }
    count1=i-1;
    
    for(i=0;i<count1;i++,count2=0)
    {
        
        for(j=0;j!=datai;j++)                       //依次查每一时间匹配的数据
        {
            
            check1=strncmp(when1[i],data[j].TIME,6);
            check2=strncmp(when2[i],data[j].TIME,6);
            
            if(check1<=0&&check2>=0)
            {
                printf("%s,%s,%s,%s,%s;\n",data[j].TIME,data[j].ID,data[j].ROOM,
                       data[j].SAFTY,data[j].ACTION);
                count2++;                         //若查询到则count2递加
            }
        }
        

        
        if(count2==0)
        {    
              montha=when1[i][2];
              monthb=when1[i][3];
              month1=(montha-48)*10+monthb-48;
              monthc=when2[i][2];
              monthd=when2[i][3];
              month2=(monthc-48)*10+monthd-48;
              daya=when1[i][4];
              dayb=when1[i][5];
              day1=(daya-48)*10+dayb-48;
              dayc=when2[i][4];
              dayd=when2[i][5];
              day2=(dayc-48)*10+dayd-48;
              
            if(day1<=year[month1-1]&&day1>0&&day2<=year[month2-1]&&day2>0&&day1<=day2)
            {
                printf("No record!\n");     //若count2没有递加,且数据都正确,输出no record
            }
            else if(day1>year[month1-1]||day1<=0||day2>year[month2-1]||day2<=0||day1>day2)
            {
                printf("Wrong Date!\n");    //若count2没有递加,且任一数据错误,wrong date
            }
        }
    }
}


void place(struct DATA data[])
{
    int i,j,check=1,count1=0,count2=0;
    char where[10][15]={'\0'};
    char com3[2]={'0'}, com4[2]={'#'};
    
    for(i=0;check!=0;i++)
    {
        scanf("%s",where[i]);                      //输入要查询的同学id
        strncpy(com3,where[i],1);
        check=strcmp(com3,com4);                 //同上
    }
    count1=i-1;                                  //获取一共多少名同学
    
    for(i=0;i<count1;i++,count2=0)
    {
        for(j=0;j!=datai;j++)                      //依次查每一位同学匹配的数据
        {
            check=strcmp(where[i],data[j].ROOM);     //若id匹配 则令check=0
            if(check==0)
            {
                printf("%s,%s,%s,%s,%s;\n",data[j].TIME,data[j].ID,data[j].ROOM,
                       data[j].SAFTY,data[j].ACTION);
                count2++;                        //若有输出 则count2递加
            }
        }
        if(count2==0) printf("No record!\n");    //若count2没有递加,说明无匹配数据,输出no record
    }
}
2019-01-07 11:24
风从南方来
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2019-1-7
  得分:0 
基本要求如下
附件: 您没有浏览附件的权限,请 登录注册
2019-01-07 11:27
风从南方来
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2019-1-7
  得分:0 
另外 测试数据如下 1,2,3组OJ判正确 4,5,6组OJ判time limit exceeded或者wrong answer
INPUT
1  
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
#  
2  
51161214036  
10182100168  
12345678901  
#  
0
OUTPUT
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
No record!


INPUT
1  
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
#  
3  
181222 181223  
181224 181224  
181225 181225  
181226 181225  
181231 181232  
#  
0

OUTPUT
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
No record!  


INTPUT
1  
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
#  
4  
A440  
A418  
A555  
#  
0

OUTPUT
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
No record!


INPUT
1  
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
#  
1  
181225081849,10182100168,A455,Normal,IN;  
181225092406,51161214036,A555,Fail,IN;  
181225092637,10182100168,A455,Normal,OUT;  
181225092934,51161214036,A440,Normal,IN;  
181225101218,10182100168,A455,Normal,IN;  
#  
2  
10182100168  
#  
0

OUTPUT
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181225081849,10182100168,A455,Normal,IN;  
181225092637,10182100168,A455,Normal,OUT;  
181225101218,10182100168,A455,Normal,IN;


INPUT
1  
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
#  
1  
181225081849,10182100168,A455,Normal,IN;  
181225092406,51161214036,A555,Fail,IN;  
181225092637,10182100168,A455,Normal,OUT;  
181225092934,51161214036,A440,Normal,IN;  
181225101218,10182100168,A455,Normal,IN;  
#  
3  
181224 181225  
#  
0

OUTPUT
181224155623,51161214036,A418,Fail,IN;  
181225081849,10182100168,A455,Normal,IN;  
181225092406,51161214036,A555,Fail,IN;  
181225092637,10182100168,A455,Normal,OUT;  
181225092934,51161214036,A440,Normal,IN;  
181225101218,10182100168,A455,Normal,IN;


INPUT
1  
181221135757,51161214036,A317,Normal,IN;  
181221143248,51161214036,A317,Normal,OUT;  
181222142817,10182100168,A455,Normal,IN;  
181222164718,10182100168,A455,Normal,OUT;  
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181224155623,51161214036,A418,Fail,IN;  
#  
1  
181225081849,10182100168,A455,Normal,IN;  
181225092406,51161214036,A555,Fail,IN;  
181225092637,10182100168,A455,Normal,OUT;  
181225092934,51161214036,A440,Normal,IN;  
181225101218,10182100168,A455,Normal,IN;  
#  
4  
A440  
A555  
#  
0

OUTPUT
181223090057,51161214036,A440,Normal,IN;  
181223200918,51161214036,A440,Normal,OUT;  
181225092934,51161214036,A440,Normal,IN;  
181225092406,51161214036,A555,Fail,IN;
2019-01-07 11:36
libaoquanccc
Rank: 2
等 级:论坛游民
帖 子:24
专家分:39
注 册:2019-1-5
  得分:10 
函数声明,不应该放在主函数里面吧。。。
2019-01-08 09:24
风从南方来
Rank: 1
等 级:新手上路
帖 子:5
专家分:5
注 册:2019-1-7
  得分:0 
回复 4楼 libaoquanccc
还有吗?
2019-01-10 22:29
豆豆的滴
Rank: 9Rank: 9Rank: 9
来 自:湖南
等 级:贵宾
威 望:31
帖 子:359
专家分:1040
注 册:2018-5-7
  得分:10 
也许oj上的更加严格呢
2019-01-11 09:35







关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034194 second(s), 9 queries.
Copyright©2004-2019, BCCN.NET, All Rights Reserved