谁是开门关门的人?(10分)
题目要求:
每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签
到、签离记录,请根据记录找出当天开门和关门的人。
具体的输入输出格式规定如下:
输入格式:测试输入的第一行给出记录的总天数N ( > 0 )。下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M行,每行的格式为
证件号码签到时间签离时间
其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
输出格式:对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,
且没有多人同时签到或者签离的情况。
要求完整的输入输出如下:
输入:

结果:

源代码如下:
/* zju.h
Copyright (c) 2002, 2006 by ctu_85
All Rights Reserved.
*/
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#define idlength 15
struct Person
{
char id[idlength+1];
char Log[10];
char Leave[10];
};
struct Day
{
Person *work;
int number;
};
struct Day *CreateDayLog(int);
struct Person *CreatePersonLog(int);
int Process(struct Person *,char *);
struct Person *Earliest(struct Day*);
struct Person *Latiest(struct Day*);
int main()
{
int i,j,k;
Day *process;
Person *p;
printf("\nPlease Enter The Days:");
scanf("%d",&i);
process=CreateDayLog(i);
for(j=0;j<i;j++)
{
printf("\nIn %dth day:\n",j+1);
if((process+j)->number!=0)
{
p=Earliest(process+j);
printf("The earliest user and his info is:\n");
printf("%s,%s,%s",p->id,p->Log,p->Leave);
printf("\n");
p=Latiest(process+j);
printf("The latiest user and his info is:\n");
printf("%s,%s,%s",p->id,p->Log,p->Leave);
}
else
printf("There is no user that day!\n");
}
return 1;
}
struct Day *CreateDayLog(int i)
{
int j,k;
struct Day *day=(struct Day *)malloc(i*sizeof(struct Day));
for(j=0;j<i;j++)
{
printf("\nThe number of users of the %dth day",j+1);
scanf("%d",&k);
(day+j)->number=k;
(day+j)->work=CreatePersonLog(k);
}
return day;
}
struct Person *CreatePersonLog(int i)
{
int j;
Person *user=(struct Person*)malloc(sizeof(struct Person)*i);
char detail[idlength+20],*t;
gets(detail);
for(j=0;j<i;j++)
{
printf("\nThe deatails of the %dth person\n",j+1);
t=gets(detail);
Process(user+j,t);
}
return user;
}
int Process(struct Person *p,char *c)
{
int i=0,j=0,k=0,status=0;
char time[8];
for(;*c!='\0';c++)
{
if(*c==' ')
{
if(status==0)
{
p->id[i]='\0';
status++;
continue;
}
if(status==1)
status++;
}
if(*c!=' ')
{
if(status==0) /* Now meets the id */
{
p->id[i]=*c;
i++;
}
else
if(status==1) /*Now meets the log time */
{
p->Log[j]=*c;
j++;
}
else
if(status==2) /*Now meets the leave time */
{
p->Leave[k]=*c;
k++;
}
}
}
p->id[i]=p->Log[j]=p->Leave[k]='\0';
}
struct Person *Earliest(struct Day* day)
{
int minhour=25,minminute=61,minsecond=61;
int i,early,temphour,tempminu,tempsec;
struct Person *p=day->work,*result;
result=p;
for(i=0;i<day->number;i++,p++)
{
temphour=(p->Log[0]-'0')*10+(p->Log[1]-'0');
tempminu=(p->Log[3]-'0')*10+(p->Log[4]-'0');
tempsec=(p->Log[6]-'0')*10+(p->Log[7]-'0');
if(temphour<minhour)
{
minhour=temphour;
minminute=tempminu;
minsecond=tempsec;
early=i;
}
else if(temphour==minhour&&tempminu<minminute)
{
minminute=tempminu;
minsecond=tempsec;
early=i;
}
else if(temphour==minhour&&tempminu==minminute&&tempsec<minsecond)
{
minsecond=tempsec;
early=i;
}
}
return result+early;
}
struct Person *Latiest(struct Day* day)
{
int maxhour=-23,maxminute=-59,maxsecond=-59;
int i,late,temphour,tempminu,tempsec;
struct Person *p=day->work,*result;
result=p;
for(i=0;i<day->number;i++,p++)
{
temphour=(p->Leave[0]-'2')*10+(p->Leave[1]-'3');
tempminu=(p->Leave[3]-'5')*10+(p->Leave[4]-'9');
tempsec=(p->Leave[6]-'5')*10+(p->Leave[7]-'9');
if(temphour>maxhour)
{
maxhour=temphour;
maxminute=tempminu;
maxsecond=tempsec;
late=i;
}
else if(temphour==maxhour&&tempminu>maxminute)
{
maxminute=tempminu;
maxsecond=tempsec;
late=i;
}
else if(temphour==maxhour&&tempminu==maxminute&&tempsec>maxsecond)
{
maxsecond=tempsec;
late=i;
}
}
return result+late;
}
了解更多浙大研究生复试解答请点击
http://blog.csdn.net/ctu_85/archive/2006/10/15/1334936.aspx
http://blog.csdn.net/ctu_85/archive/2006/10/30/1357145.aspx
http://blog.csdn.net/ctu_85/archive/2006/10/31/1357794.aspx
浙江大学ACM试题解答(四月)
http://blog.csdn.net/ctu_85/archive/2007/04/24/1576831.aspx
浙江大学ACM试题解答(三月)
http://blog.csdn.net/ctu_85/archive/2007/03/20/1535556.aspx
麻省理工算法导论翻译
http://blog.csdn.net/ctu_85/archive/2007/06/08/1643179.aspx
华容道游戏与算法
http://blog.csdn.net/ctu_85/archive/2007/05/15/1610722.aspx
中国象棋对战程序C语言源代码
http://blog.csdn.net/ctu_85/archive/2007/05/04/1596351.aspx
软件可行性报告
http://blog.csdn.net/ctu_85/archive/2006/06/06/775894.aspx
软件需求分析报告
http://blog.csdn.net/ctu_85/archive/2006/06/06/775892.aspx
发表于 @ 2006年10月16日 03:08:00|评论(loading...)|编辑