错误点:
没有用map,导致超时。
用错了下标,答案错误,没有赋初值,段错误。。。
使用%d输出固定位的东西不加%06d。。
ps:map,想sort,害得用vector。
#include<bits/stdc++.h>
using namespace std;
struct student{string id;int date;int score;int site;char rank;
}stu[10000];
struct stt{int site;int num=0;
}st[1000000];
bool cmp(student a,student b){if(a.score!=b.score) return a.score>b.score;else return a.id<b.id;
}
bool cmp2(stt a,stt b){if(a.num!=b.num) return a.num>b.num;else return a.site<b.site;
}
int main(){int n,m;scanf("%d %d",&n,&m);for(int i=0;i<n;i++){cin>> stu[i].id >> stu[i].score;stu[i].date=stoi(stu[i].id.substr(4,6));stu[i].site=stoi(stu[i].id.substr(1,3));stu[i].rank=stu[i].id[0];//printf("%d %d %d\n",stu[i].date,stu[i].site,stu[i].rank);}int type;for(int i=0;i<m;i++){scanf("%d",&type);if(type==1){char a;getchar();scanf("%c",&a);vector<student> q; for(int j=0;j<n;j++){if(stu[j].rank==a){q.push_back(stu[j]);}}sort(q.begin(),q.end(),cmp);printf("Case %d: %d %c\n",i+1,type,a);if(q.size())for(int j=0;j<q.size();j++){printf("%s %d\n",q[j].id.c_str(),q[j].score);}else printf("NA\n");}else if(type==2){int a;scanf("%d",&a);int cnt=0;int sum=0;for(int j=0;j<n;j++){if(stu[j].site==a){cnt++;sum+=stu[j].score;}}printf("Case %d: %d %03d\n",i+1,type,a);if(cnt!=0)printf("%d %d\n",cnt,sum);else printf("NA\n");}else if(type==3){int a;scanf("%d",&a);map<int,int> mp;for(int j=0;j<n;j++){if(stu[j].date==a){mp[stu[j].site]++;}}vector<stt> q;stt temp;printf("Case %d: %d %06d\n",i+1,type,a);for(map<int ,int>::iterator it=mp.begin();it!=mp.end();it++){temp.site=it->first;temp.num=it->second;q.push_back(temp);}sort(q.begin(),q.end(),cmp2);if(mp.size())for(int j=0;j<q.size();j++){printf("%d %d\n",q[j].site,q[j].num);}else{printf("NA\n");}}else{string a;cin >> a;printf("Case %d: %d %s\n",i+1,type,a.c_str());printf("NA\n");}}return 0;
}