#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct Stu
{
char s[20];
char grade;
int room;
int date;
int exam;
int score;
}stu[10100];
struct roo
{
int kch;
int rs;
}kc[1010];
bool cmp(Stu a,Stu b)
{
if (a.score != b.score)
return a.score > b.score;
else if (strcmp(a.s, b.s) < 0)
return 1;
else
return 0;
}
bool com(roo a,roo b)
{
if (a.rs != b.rs)
return a.rs > b.rs;
else
return a.kch < b.kch;
}
int find1(char gra,int n)
{
int flag = 0;
sort(stu, stu + n, cmp);
for (int i = 0; i < n; i++)
{
if (stu[i].grade == gra)
{
printf("%s %d\n", stu[i].s, stu[i].score);
flag = 1;
}
}
if (!flag)
printf("NA\n");
return 0;
}
int find2(int num,int n)
{
int cou = 0, sum = 0;
for (int i = 0; i < n; i++)
{
if (stu[i].room == num)
{
cou++;
sum += stu[i].score;
}
}
if (cou == 0)
printf("NA\n");
else
printf("%d %d\n", cou, sum);
return 0;
}
int find3(int num,int n)
{
int flag = 0;
for (int i = 101; i <= 999; i++)
kc[i].kch = i;
for (int i = 0; i < n; i++)
{
if (stu[i].date == num)
{
kc[stu[i].room].rs++;
flag = 1;
}
}
sort(kc, kc + 1010, com);
for (int i = 0; i < 1010; i++)
{
if (kc[i].rs)
printf("%d %d\n", kc[i].kch, kc[i].rs);
}
if (!flag)
printf("NA\n");
for (int i = 0; i < 1010; i++)
{
kc[i].rs = 0;
kc[i].kch = 0;
}
return 0;
}
int main()
{
int n, m;
int sea;
char gra;
int num;
scanf("%d%d", &n, &m);
getchar();
for (int i = 0; i < n; i++)
{
scanf("%s", stu[i].s);
stu[i].grade = stu[i].s[0];
stu[i].room = (stu[i].s[1] - '0') * 100 + (stu[i].s[2] - '0') * 10 + (stu[i].s[3] - '0');
stu[i].date = (stu[i].s[4] - '0') * 100000 + (stu[i].s[5] - '0') * 10000 + (stu[i].s[6] - '0') * 1000 + (stu[i].s[7] - '0') * 100 + (stu[i].s[8] - '0') * 10 + (stu[i].s[9] - '0');
stu[i].exam = (stu[i].s[10] - '0') * 100 + (stu[i].s[11] - '0') * 10 + (stu[i].s[12] - '0');
scanf("%d", &stu[i].score);
}
for (int i = 1; i <= m; i++)
{
scanf("%d", &sea);
if (sea == 1)
{
scanf(" %c", &gra);
printf("Case %d: %d %c\n",i, sea, gra);
find1(gra,n);
}
else if (sea == 2)
{
scanf("%d", &num);
printf("Case %d: %d %d\n", i, sea, num);
find2(num,n);
}
else
{
scanf("%d", &num);
printf("Case %d: %d %06d\n", i, sea, num);//最后一个测试点
find3(num,n);
}
}
return 0;
}
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct Stu{
char s[20];
char grade;
int room;
int date;
int exam;
int score;
}stu[10100];
struct roo{
int kch;
int rs;
}kc[1010];
bool cmp(Stu a,Stu b){
if (a.score != b.score)
return a.score > b.score;
else if (strcmp(a.s, b.s) < 0)
return 1;
else
return 0;
}
bool com(roo a,roo b){
if (a.rs != b.rs)
return a.rs > b.rs;
else
return a.kch < b.kch;
}
int find1(char gra,int n){
int flag = 0;
sort(stu, stu + n, cmp);
for (int i = 0; i < n; i++)
{
if (stu[i].grade == gra)
{
printf("%s %d\n", stu[i].s, stu[i].score);
flag = 1;
}
}
if (!flag)
printf("NA\n");
return 0;
}
int find2(int num,int n){
int cou = 0, sum = 0;
for (int i = 0; i < n; i++)
{
if (stu[i].room == num)
{
cou++;
sum += stu[i].score;
}
}
if (cou == 0)
printf("NA\n");
else
printf("%d %d\n", cou, sum);
return 0;
}
int find3(int num,int n){
int flag = 0;
for (int i = 101; i <= 999; i++)
kc[i].kch = i;
for (int i = 0; i < n; i++)
{
if (stu[i].date == num)
{
kc[stu[i].room].rs++;
flag = 1;
}
}
sort(kc, kc + 1010, com);
for (int i = 0; i < 1010; i++)
{
if (kc[i].rs)
printf("%d %d\n", kc[i].kch, kc[i].rs);
}
if (!flag)
printf("NA\n");
for (int i = 0; i < 1010; i++)
{
kc[i].rs = 0;
kc[i].kch = 0;
}
return 0;
}
int main(){
int n, m;
int sea;
char gra;
int num;
scanf("%d%d", &n, &m);
getchar();
for (int i = 0; i < n; i++)
{
scanf("%s", stu[i].s);
stu[i].grade = stu[i].s[0];
stu[i].room = (stu[i].s[1] - '0') * 100 + (stu[i].s[2] - '0') * 10 + (stu[i].s[3] - '0');
stu[i].date = (stu[i].s[4] - '0') * 100000 + (stu[i].s[5] - '0') * 10000 + (stu[i].s[6] - '0') * 1000 + (stu[i].s[7] - '0') * 100 + (stu[i].s[8] - '0') * 10 + (stu[i].s[9] - '0');
stu[i].exam = (stu[i].s[10] - '0') * 100 + (stu[i].s[11] - '0') * 10 + (stu[i].s[12] - '0');
scanf("%d", &stu[i].score);
}
for (int i = 1; i <= m; i++)
{
scanf("%d", &sea);
if (sea == 1)
{
scanf(" %c", &gra);
printf("Case %d: %d %c\n",i, sea, gra);
find1(gra,n);
}
else if (sea == 2)
{
scanf("%d", &num);
printf("Case %d: %d %d\n", i, sea, num);
find2(num,n);
}
else
{
scanf("%d", &num);
printf("Case %d: %d %06d\n", i, sea, num);//最后一个测试点
find3(num,n);
}
}
return 0;
}