1 条题解
-
0
C :
#include <stdio.h> #include <string.h> typedef struct { int no; int h,m; int tag; }Node; Node arry[105]; int main() { int no,h,m; char op; int times,avetime; memset(arry,0,sizeof(arry)); times = 0 , avetime = 0; while( scanf( "%d" , &no ) && no != -1) { scanf(" %c %d:%d" , &op , &h , &m ); if( no == 0 ) //表示当前这组数据输入完毕,准备输出 { if( times == 0 ) printf( "0 0\n" ); //如果输入次数为0的时候 else { //四舍五入 if( avetime*1.0/times - avetime/times >= 0.5 ) avetime = avetime / times + 1; else avetime = avetime/times; printf( "%d %d\n" , times , avetime ); } //清零,准备记录下一组数据 memset(arry,0,sizeof(arry)); times = 0 , avetime = 0; } else { if( op == 'S' && arry[no].tag == 0 ) //开始op == 'S',并且以前没有开始过arry[no].tag == 0 { arry[no].h = h , arry[no].m = m; arry[no].tag = 1; } else if( op == 'E' && arry[no].tag == 1 ) //结束op == 'E',并且开始过arry[no].tag == 1 { int time = (h-arry[no].h)*60 - arry[no].m + m; avetime += time; times++; arry[no].tag = 0; } } } return 1; }
C++ :
#include <cstdio> #include <algorithm> using namespace std; int main() { while (true) { int k; scanf("%d", &k); if (-1 == k) break; char ss[10]; int h, m, a[105], cnt = 0; double sum = 0; scanf("%s %d:%d", ss, &h, &m); fill(a, a + 105, -1); while (k > 0) { int x = h * 60 + m; if (ss[0] == 'S') { if (a[k] == -1) a[k] = x; } else { if (a[k] != -1) { sum += x - a[k]; ++cnt; a[k] = -1; } } scanf("%d %s %d:%d", &k, ss, &h, &m); } if (0 == cnt) puts("0 0"); else printf("%d %.0f\n", cnt, sum / cnt + 1e-8); } return 0; }
- 1
信息
- ID
- 2158
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者