1025 问题代码,有一case未过

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAX 30010
using namespace std;
int n;
struct User
{
char id[15];
int grade;
int fr , loc , lr;
}user[MAX];
int cnt = 0;
bool cmp(User a , User b)
{
if(a.grade != b.grade)
return a.grade > b.grade;
else
return strcmp(a.id , b.id) < 0;
}
int main()
{
scanf("%d" , &n);
int k;
int i , j;
int loc;
int now;
for(i = 0 ; i < n ; ++i)
{
scanf("%d" , &k);
loc = i +1 ;
now = cnt;
for(j = 0 ; j < k ; ++j)
{
scanf("%s %d" , user[cnt].id , &user[cnt].grade);
user[cnt].loc = loc;
++cnt;
}
sort(user + now , user + cnt , cmp);
user[now].lr = 1;
for(j =now ; j < cnt ; ++j)
{
if(user[j].grade == user[j-1].grade)
{
user[j].lr = user[j-1].lr;
}
else
{
user[j].lr = j + 1 - now;
}
}
}
sort(user , user + cnt , cmp);
user[0].fr = 1;
for(i =1 ; i < cnt ; ++i)
{
if(user[i].grade == user[i-1].grade)
{
user[i].fr = user[i-1].fr;
}
else
{
user[i].fr = i+1;
}
}
printf("%d\n" , cnt);
for(i = 0 ; i < cnt ; ++i)
{
printf("%s %d %d %d\n" , user[i].id , user[i].fr , user[i].loc , user[i].lr);
}
return 0;
}

热评文章