【杭电】[1084]What Is Your Grade?

文章字数:184

问题描述

问题分析

不使用sort排序的话
就可以统计超过自己的个数
与总个数的一半比较

 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;
}

题目地址:【杭电】[1084]What Is Your Grade?

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...