题很简单,但是今天遇到了一个大坑,就是输入用了while(scanf("%d", &id) ),虽然输入-1程序也能正常结束,但是一直WA,后来用while(scanf("%d", &id) != EOF)就过了,,,
#include <stdio.h>
#include <map>
using namespace std;
struct Node
{
bool start;
int sh, sm;
};
map<int, Node> dict;
int main()
{
int id, hour, minutes;
char c;
int cnt = 0, tmp = 0;
while(scanf("%d", &id) != EOF)
{
if(id == -1)
break;
getchar(); //吃空格
scanf("%c %d:%d", &c, &hour, &minutes);
if(id == 0)
{
if(cnt)
printf("%d %.0f\n", cnt, (double)tmp/cnt);
else
printf("0 0\n");
dict.clear();
cnt = 0, tmp = 0;
continue;
}
if(c == 'S')
{
dict[id].sh = hour, dict[id].sm = minutes;
dict[id].start = true;
}
else
{
if(dict[id].start)
{
cnt++;
tmp += minutes - dict[id].sm + (hour-dict[id].sh)*60;
}
}
}
return 0;
}