zju2007游船出租

http://acm.hdu.edu.cn/showproblem.php?pid=1861

浙大计算机研究生复试上机考试-2007年

#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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值