九度OnlineJudge之1022:游船出租
题目描述: #include <string>#include <iostream>#include <cstring>#include <map>using namespace std;struct Note{ int id; char ch; string s; string e; };inline int getInt(string str){ int s1 = str[0]-'0'; int s2 = str[1]-'0'; int s3 = str[3]-'0'; int s4 = str[4]-'0'; return (s1*10+s2)*60 + s3*10+s4; }int flag1[101];int flag2[101];int main(){ int N; char ch; string time; map<int,Note> m; while(cin>>N,N!=-1) { cin>>ch>>time; if(N==0) { int k=0; int sum=0; for(int i=1;i<=100;i++) { if(flag1[i]==1&&flag2[i]==1) { ++k; string start = m[i].s; string end = m[i].e; int a = getInt(start); int b = getInt(end); sum+=b-a; } } if(k==0) cout<<"0 0"<<endl; else cout<<k<<" "<<int((double)sum/k+0.5)<<endl; m.clear(); memset(flag1,0,sizeof(flag1)); memset(flag2,0,sizeof(flag2)); continue; } else { Note n; n.ch = ch; n.id = N; if(ch=='S') { n.s = time; flag1[N]=1; m.insert(make_pair(N,n)); } if(ch=='E' && flag1[N]==1) { m[N].e = time; flag2[N]=1; } } } // system("PAUSE"); return 0;}