PAT admission number consists of 4 parts:
- The first is the level, that is, # T # stands for the top level; A represents class A; B represents class B;
- The 2nd to 4th digits are the examination room number, ranging from 101 to 999;
- The 5th to 10th places are the examination date, and the format is year, month and day, accounting for 2 places in sequence;
- The last 11 ~ 13 digits are the candidate number, ranging from 000 to 999.
A series of examinees' admission numbers and their scores are given. Please output various statistical information as required.
Input format:
Input: first, give two positive integers N (≤ 104) and M (≤ 100) in one line, which are the number of candidates and the number of statistical requirements respectively.
Next, in line N, each line gives an examinee's admission number and its score (an integer in the interval [0100]), which are separated by spaces.
After the examinee's information, give the "M" line, and each line gives a statistical requirement. The format is: type instruction, where
- Type 1 means that the scores of candidates at a specified level are required to be output in non ascending order of scores, and the corresponding instruction gives the letters representing the specified level;
- Type 2 indicates that it is required to output the statistics of the number and total score of candidates in a designated examination room, and the corresponding instruction gives the number of the designated examination room;
- Type 3 indicates that the number of candidates on a specified date is required to be statistically output in the examination room, and the corresponding instruction gives the specified date in the same format as the date on the admission ticket.
Output format:
For each statistical requirement, first output # Case #: requirement in one line, where # is the number of the requirement, starting from 1; Requirement} that is, copy the requirements given by the input. Then output the corresponding statistical results:
- For the instruction of type 1, the output format is the same as the input examinee information format, that is, the result of the examination permit number. For examinees with parallel scores, output them incrementally according to the dictionary order of their admission number (the title shall ensure that there is no duplicate admission number);
- The instruction of type 2 is output in the format of "total score";
- For instructions of type ^ 3, the output is in non increasing order, and the format is ^ examination room number and total number of people. If the number of people is in parallel, it will be output in the order of increasing the examination room number.
If the query result is empty, NA will be output.
Input sample:
8 4 B123180908127 99 B102180908003 86 A112180318002 98 T107150310127 62 A107180908108 100 T123180908010 78 B112160918035 88 A107180908021 98 1 A 2 107 3 180908 2 999
Output example:
Case 1: 1 A A107180908108 100 A107180908021 98 A112180318002 98 Case 2: 2 107 3 260 Case 3: 3 180908 107 2 123 2 102 1 Case 4: 2 999 NA
Test points 1 and 4: there is no leading 0 when the third output
Test point 3: the first sort overflows. Change the examination room number to long long and then * 1000000000 (help me, this is really a good way to write
I've learned that if you want to sort the values of map, you can first use vector < pair < int, int > > V (MP. Begin(), MP End()) save the map, and then bool CMP (pair < int, int > A, pair < int, int > b), which writes return a.Second > b.second; When accessing, you can use the iterator it - > first access key of vector and it - > second access value to realize sorting
This problem has been stuck for a long time, and the code is extremely ugly. My idea is so strange that I have to rewrite it later
#include<bits/stdc++.h> using namespace std; int c=1; typedef struct sad{ char lev; int kaochang,day,id,gra; }stu; int cmp1(stu a,stu b) { if(a.lev!=b.lev)return a.lev>b.lev; else if(a.gra!=b.gra)return a.gra>b.gra; else{ long long A=(long long)a.kaochang*1000000000+a.day*1000+a.id; long long B=(long long)b.kaochang*1000000000+b.day*1000+b.id; return A<B; } } void f1(int type,char key,stu s[],int n) { printf("Case %d: %d %c\n",c++,type,key); sort(s,s+n,cmp1); int x=0; for(int i=0;i<n;i++){ if(s[i].lev==key){ printf("%c%03d%06d%03d %d\n",s[i].lev,s[i].kaochang,s[i].day,s[i].id,s[i].gra); x=1; } else if(x)break; } if(x==0)printf("NA\n"); } int cmp2(stu a,stu b) { return a.kaochang>b.kaochang; } void f2(int type,int key,stu s[],int n) { printf("Case %d: %d %d\n",c++,type,key); sort(s,s+n,cmp2); int sum=0,num=0; for(int i=0;i<n;i++){ if(s[i].kaochang==key){ num++; sum+=s[i].gra; } else if(num)break; } if(!num)printf("NA\n"); else printf("%d %d\n",num,sum); } int cmp3(stu a,stu b) { if(a.day!=b.day)return a.day>b.day; else return a.kaochang>b.kaochang; } int cmp4(pair<int,int> a,pair<int,int> b) { if(a.second!=b.second)return a.second>b.second; else return a.first<b.first; } void f3(int type,int key,stu s[],int n) { printf("Case %d: %d %06d\n",c++,type,key);//This 06 card has test point 14 map<int,int> num; sort(s,s+n,cmp3); int x=0; for(int i=0;i<n;i++){ if(s[i].day==key){ x=1; if(num.find(s[i].kaochang)==num.end())num[s[i].kaochang]=1; else num[s[i].kaochang]++; } else if(x)break; } if(x==0)printf("NA\n"); else{ vector<pair<int,int> > v(num.begin(),num.end()); sort(v.begin(),v.end(),cmp4); for(auto it=v.begin();it!=v.end();it++){ printf("%d %d\n",it->first,it->second); } } } int main() { int n,m; scanf("%d%d",&n,&m); stu s[n]; for(int i=0;i<n;i++){ getchar(); scanf("%c%3d%6d%3d %d",&s[i].lev,&s[i].kaochang,&s[i].day,&s[i].id,&s[i].gra); } for(int i=0;i<m;i++){ int t; scanf("%d",&t); if(t==1){ char k; getchar(); scanf("%c",&k); f1(t,k,s,n); } else if(t==2){ int k; scanf("%d",&k); f2(t,k,s,n); } else if(t==3){ int k; scanf("%d",&k); f3(t,k,s,n); } } return 0; }