这题目我想到的是栈,当然感觉也是想多了,,
#include<stdio.h> #include<stack> #include<math.h> using namespace std; double round(double r) { return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5); } stack<int>data[100]; int sum; int num; int pre; void init(){ for(int i=0;i<100;i++){ while(!data[i].empty()) data[i].pop(); } sum=0;num=0;pre=0; } int main(){ int n,a,b; char c; init(); while(1){ scanf("%d",&n); if(n==-1)break; scanf(" %c %d:%d",&c,&a,&b); int t=a*60+b; if(n==0){ if(num==0) printf("0 0\n"); else printf("%d %d\n",num,(int)round((double)sum/num)); init(); } else{ pre=t; if(c=='S') data[n].push(t); else if(c=='E'){ if(data[n].empty()) continue; int time=data[n].top(); data[n].pop(); sum+=t-time;num++; } } } return 0; }
时间: 2024-11-05 18:39:46