水水更健康吧,好几天木有A题了。
字符串处理、四舍五入。
代码如下:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 1000
int main()
{
int i, j;
int n;
double len;
int team;
char str[LEN];
int h, m, s;
int alltime;
scanf("%d%lf", &n, &len);
while(scanf("%d",&team) != EOF)
{
alltime = 0;
int g = 1;
for(i = 0; i < n; i++)
{
if(scanf("%d:%d:%d", &h, &m, &s) == 3)
{
alltime += h * 3600 + m * 60 + s;
}
else
{
gets(str);
g = 0;
printf("%3d: -\n", team);
break;
}
}
if(g == 1)
{
double v = 1.0 * alltime / len;
int alltimeint = (int)(v + 0.5);
int mout = alltimeint / 60;
int sout = alltimeint % 60;
printf("%3d: %d:", team, mout);
if(sout / 10 == 0)
printf("0%d ", sout);
else if(sout == 0)
printf("00 ");
else
printf("%d ", sout);
printf("min/km\n");
}
}
//system("pause");
return 0;
}
posted on 2012-09-17 20:08
小鼠标 阅读(142)
评论(0) 编辑 收藏 引用 所属分类:
水题