http://acm.hdu.edu.cn/showproblem.php?pid=1861
#include <stdio.h>
#include <string.h>
struct Node
{
int no;
int h,m;
int tag;
}a[105]; //保存第i号船的时间信息
int main()
{
int h,m,no;
char ch;
memset(a,0,sizeof(a)); //不能放在while循环内,多组数据输入之间有求和关系
int times=0,avetime=0; //不能每次输入都清空
while (scanf("%d",&no)&& no!=-1)
{
scanf(" %c %d:%d",&ch,&h,&m);
if (no==0)
{
if (times==0)
{
printf("0 0\n");
}
else
{
if (avetime*1.0/times - avetime/times >=0.5)
{
avetime=avetime/times+1;
}
else
{
avetime/=times;
}
printf("%d %d\n",times,avetime);
}
memset(a,0,sizeof(a)); //一天的数据求和完毕,清空变量
times=0,avetime=0;
}
else
{
if (ch=='S'&&a[no].tag==0)
{
a[no].h=h;
a[no].m=m;
a[no].tag=1;
}
else if (ch=='E'&&a[no].tag==1)
{
int time=(h-a[no].h)*60-a[no].m+m; //计算累加时间
avetime+=time; //所以另外定义中间变量保存每艘船的时间
times++;
a[no].tag=0;
}
}
}
return 0;
}