-
Notifications
You must be signed in to change notification settings - Fork 0
/
10825.cpp
88 lines (80 loc) · 1.75 KB
/
10825.cpp
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
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
typedef long long lld;
struct member
{
char name[14];
int k, e, m;
};
struct member stu[100000], tmp[100000];
bool dic(char *a, char *b)
{
int lenk = strlen(a)<strlen(b)?strlen(a):strlen(b);
char atmp = a[0], btmp = b[0];
if(a[0]>='a') atmp -= 32;
if(b[0]>='a') btmp -= 32;
if(atmp<btmp) return true;
else if(atmp>btmp) return false;
for(int i=1;i<lenk;i++)
{
if(a[i]<b[i]) return true;
else if(a[i]>b[i]) return false;
else if(i == lenk-1)
{
if(lenk==strlen(a)) return true;
else if(lenk==strlen(b)) return false;
}
}
}
void merge(struct member *a, int p, int q, int r)
{
int pos = p, posa = p, posb = q+1;
while(posa<=q&&posb<=r)
{
if (a[posa].k>a[posb].k) tmp[pos++] = a[posa++];
else if (a[posa].k<a[posb].k) tmp[pos++] = a[posb++];
else
{
if (a[posa].e<a[posb].e) tmp[pos++] = a[posa++];
else if (a[posa].e>a[posb].e) tmp[pos++] = a[posb++];
else
{
if (a[posa].m>a[posb].m) tmp[pos++] = a[posa++];
else if (a[posa].m<a[posb].m) tmp[pos++] = a[posb++];
else
{
if(dic(a[posa].name, a[posb].name))
tmp[pos++] = a[posa++];
else tmp[pos++] = a[posb++];
}
}
}
}
while(posa<=q)
tmp[pos++] = a[posa++];
while(posb<=r)
tmp[pos++] = a[posb++];
for(int i=p;i<=r;i++)
a[i] = tmp[i];
}
void mergesort(struct member *a, int p, int r)
{
if(p<r)
{
int q = (p+r)/2;
mergesort(a, p, q);
mergesort(a, q+1, r);
merge(a, p, q, r);
}
}
int main()
{
int n;
scanf(" %d", &n);
for(int i=0;i<n;i++)
scanf(" %s %d %d %d", stu[i].name, &stu[i].k, &stu[i].e, &stu[i].m);
mergesort(stu, 0, n-1);
for(int i=0;i<n;i++)
printf("%s\n", stu[i].name);
return 0;
}