题目传送门
本来想测试一下自己做题速度 但是一着急反而在读题上面犯了错误,磨磨唧唧40多分钟
题目的条件很细很繁琐
- 查询1:按照成绩降序输出某level的考生信息,如果成绩相同则按照准考证号字母序升序排列
- 查询2:根据给出的site,统计考生总成绩和人数,没啥坑
- 查询3:根据给出的date,按照site统计考生人数信息,并按照人数降序输出;如果人数相同,则按照site升序输出
- 查询3给出的
Term 可能出现前导零,输出时候需要原样进行输出,天坑!!! - 无结果输出
NA
给贴心的前辈引流了
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 10010;
int n, m;
struct node {
char level;
int site;
int date;
int number;
int score;
char ID[20];
};
node stu[N];
int cmp1(const node &A,const node &B) {
return (A.score > B.score) || (A.score == B.score && strcmp(A.ID, B.ID) < 0);
}
int cmp2(const node& A, const node& B) {
return (A.score > B.score) || (A.score == B.score && A.site < B.site);
}
int changeToInt(int tou, int wei,char *s) {
int ans = 0;
for (int j = tou; j <= wei; ++j)
ans = ans * 10 + s[j] - '0';
return ans;
}
int site_cnt[1010];
node a[1010];
void find_date(int x) {
bool flag = 0;
for (int i = 0; i <= 999; ++i) site_cnt[i] = 0;
for (int i = 1; i <= n; ++i) {
if (stu[i].date == x) {
++site_cnt[stu[i].site];
flag = 1;
}
}
if (!flag) {
printf("NA\n");
return;
}
int cnt = 0;
for (int i = 101; i <= 999; ++i) {
if (site_cnt[i] > 0) {
++cnt;
a[cnt].site = i;
a[cnt].score = site_cnt[i];
}
}
sort(a + 1, a + 1 + cnt, cmp2);
for (int i = 1; i <= cnt; ++i)
printf("%d %d\n", a[i].site, a[i].score);
}
int main()
{
char s[20];
int x;
int opt;
scanf("%d%d",&n,&m);
for (int i = 1; i <= n; ++i) {
scanf("%s %d", &stu[i].ID,&stu[i].score);
stu[i].level = stu[i].ID[0];
stu[i].site = changeToInt(1, 3, stu[i].ID);
stu[i].date = changeToInt(4, 9, stu[i].ID);
stu[i].number = changeToInt(10, 12, stu[i].ID);
}
sort(stu + 1, stu + 1 + n, cmp1);
for (int i = 1; i <= m; ++i) {
scanf("%d", &opt);
if (opt == 1) {
scanf("%s",&s);
printf("Case %d: %d %c\n",i,opt,s[0]);
bool flag = 0;
for (int j = 1; j <= n; ++j) {
if (stu[j].level == s[0]) {
printf("%s %d\n", stu[j].ID, stu[j].score);
flag = 1;
}
}
if (!flag) printf("NA\n");
}
else if (opt == 2) {
scanf("%d", &x);
printf("Case %d: %d %d\n", i, opt, x);
int ans = 0;
int cnt = 0;
bool flag = 0;
for (int j = 1; j <= n; ++j)
if (stu[j].site == x) {
ans += stu[j].score;
++cnt;
flag = 1;
}
if (flag) printf("%d %d\n",cnt,ans);
else printf("NA\n");
}
else if (opt == 3) {
scanf("%d", &x);
printf("Case %d: %d %06d\n", i, opt, x);
find_date(x);
}
}
return 0;
}
|