1141. PAT Ranking of Institutions (25)

1141. PAT Ranking of Institutions (25)

时间限制
500 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (<=105), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:

ID Score School

where "ID" is a string of 6 characters with the first one representing the test level: "B" stands for the basic level, "A" the advanced level and "T" the top level; "Score" is an integer in [0, 100]; and "School" is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that "ID" is unique for each testee.

Output Specification:

For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:

Rank School TWS Ns

where "Rank" is the rank (start from 1) of the institution; "School" is the institution code (all in lower case); "TWS" is the total weighted score which is defined to be the integer part of "ScoreB/1.5 + ScoreA + ScoreT*1.5", where "ScoreX" is the total score of the testees belong to this institution on level X; and "Ns" is the total number of testees who belong to this institution.

The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.

Sample Input:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
Sample Output:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

        实际过程就是PAT考试结束后对学校进行排名。每个学生id唯一,第一位代表考试难度。顶级成绩乘1.5,甲级直接累计,乙级成绩除以1.5,最后总分取整数,分数相同则人数少的排前,还相同则按学校id排。

        输入数据的时候将学校id统一转换成一个数字id方便计算,每输入一个学生就找到他的学校序号,把分数加上去,然后sort排序,最后输出即可。整个过程是比较多,但是还是很清晰


#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

typedef struct school {
	double sc;
	int scint;
	int ns;
	int rk;
	long long id;
}school;
int N, schcnt = 0;
school *schools[100001];
map<long long, char>itocmp;
map<char, long long>ctoimp;
map<long long, int>itoisch;
long long getn(char *cs) {
	long long res = 0;
	int i = 0;
	long long xi = 1;
	while (cs[i] != '\0') {
		res += ctoimp[cs[i]] * xi;
		xi *= 100;
		i++;
	}
	return res;
}
void getc(long long num, char *cs) {
	int i = 0;
	while (num != 0) {
		cs[i] = itocmp[num % 100];
		num /= 100;
		i++;
	}
	cs[i] = '\0';
}
int getNo(long long no) {
	if (itoisch[no] == 0) {
		schcnt++;
		itoisch[no] = schcnt;
		schools[schcnt] = (school*)malloc(sizeof(school));
		*(schools[schcnt]) = { 0 };
		schools[schcnt]->id = no;
		schools[schcnt]->scint = -1;
		return  schcnt;
	}
	else {
		return itoisch[no];
	}
}
bool cp(long long a, long long b) {
	char as[7] = { '\0' };
	char bs[7] = { '\0' };
	getc(a, as);
	getc(b, bs);
	int ap = 0, bp = 0;
	while (as[ap] != '\0'&&bs[bp] != '\0') {
		if (as[ap] != bs[bp]) return as[ap] < bs[bp];
		ap++; bp++;
	}
	if (as[ap] == '\0') return true;
	return false;
}
bool cmp(school *a, school *b) {
	if (a->scint != b->scint) return a->scint > b->scint;
	if (a->ns != b->ns) return a->ns < b->ns;
	bool f= cp(a->id, b->id);
	return f;
}

int main() {
	for (int i = 0; i < 10; i++) {
		itocmp[i] = '0' + i;
		ctoimp['0' + i] = i;
	}
	for (int i = 0; i < 26; i++) {
		itocmp[i + 10] = 'a' + i;
		ctoimp['a' + i] = i + 10;
	}
	scanf("%d\n", &N);
	char tid[7] = { '\0' };
	int tsorce;
	char tsch[7] = { '\0' };
	for (int i = 0; i < N; i++) {
		scanf("%s %d %s\n", tid, &tsorce, tsch);
		for (int j = 0; j < 6; j++) {
			if (tid[j] >= 'A'&&tid[j] <= 'Z') tid[j] += 32;
			if (tsch[j] >= 'A'&&tsch[j] <= 'Z') tsch[j] += 32;
		}
		double scd = 0.0;
		if (tid[0] == 't') {
			scd = (tsorce * 1.0) * 1.5;
		}
		else if (tid[0] == 'a') {
			scd = (tsorce*1.0);
		}
		else {
			scd = (tsorce * 1.0) / 1.5;
		}
		long long tschn = getn(tsch);
		int No = getNo(tschn);
		schools[No]->ns++;
		schools[No]->sc += scd;
	}
	for (int i = 1; i <= schcnt; i++) {
		schools[i]->scint = schools[i]->sc;
	}
	sort(schools + 1, schools + 1 + schcnt, cmp);
	printf("%d\n", schcnt);
	schools[1]->rk = 1;
	char cs[7] = { '\0' };
	getc(schools[1]->id, cs);
	printf("%d %s %d %d\n", schools[1]->rk, cs, schools[1]->scint, schools[1]->ns);
	for (int i = 2; i <= schcnt; i++) {
		getc(schools[i]->id, cs);
		if (schools[i]->scint == schools[i - 1]->scint) {
			schools[i]->rk = schools[i - 1]->rk;
		}
		else
			schools[i]->rk = i;
		printf("%d %s %d %d\n", schools[i]->rk, cs, schools[i]->scint, schools[i]->ns);
	}
	return 0;
}

原创文章 59 获赞 41 访问量 10万+

猜你喜欢

转载自blog.csdn.net/rzdyzx/article/details/79672207