[HDU] [1084] What Is Your Grade?

Problem Description

Loading...

Problem Analysis

If you don’t use sort, you can just count how many people are ahead of you and compare that with half of the total count.

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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node {
	int x;
	char s[10];
} a[120];
int main() {
	int n;
	while(scanf("%d",&n),n!=-1) {
		for(int i=0; i<n; i++) {
			scanf("%d %s",&a[i].x,&a[i].s);
		}
		int cnt[5]= {0};
		for(int i=4; i>0; i--) {
			for(int j=0; j<n; j++) {
				if(a[j].x==i)
					cnt[i]++;
			}
		}
		for(int i=0; i<n; i++) {
			if(a[i].x==5)
				printf("100\n");
			else if(a[i].x==0)
				printf("50\n");
			else {
				int t=0;
				for(int j=0; j<n; j++) {
					if(a[j].x==a[i].x&&strcmp(a[j].s,a[i].s)<0)
						t++;
				}
				if(t>=cnt[a[i].x]/2)
					printf("%d\n",100-(5-a[i].x)*10);
				else
					printf("%d\n",100-(5-a[i].x)*10+5);
			}
		}
		printf("\n");
	}
	return 0;
}

Problem link: 【HDU】[1084]What Is Your Grade?

Loading...