Day50: [PAT甲级] 1025 PAT Ranking (25分)

Day50: [PAT甲级] 1025 PAT Ranking (25分)

题源:

来自PAT真题库:

https://pintia.cn/problem-sets/994805342720868352/problems/994805474338127872

代码:

dirty code凑合看吧

#include<iostream>
#include<string>
#include<sstream>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef struct stu {
	long long id;
	int score;
	int pos;
	int rank1;
	int rank2;
}stu;
vector<stu> stus;
bool cmp(stu A,stu B) {
	if (A.score != B.score)
		return A.score > B.score;
	else {
		return A.id < B.id;
	}
}
int testNum,N;
int main() {
	cin >> testNum;
	for (int i = 1; i <= testNum; i++) {
		cin >> N;
		stu x;
		vector<stu> temp;
		for (int j = 0; j < N; j++) {
			cin >> x.id >> x.score;
			x.pos = i;
			temp.push_back(x);
		}
		sort(temp.begin(), temp.end(),cmp);
		for (int i = 0; i < temp.size(); i++) {
			if (i - 1 >= 0 && temp[i].score == temp[i - 1].score) temp[i].rank1 = temp[i - 1].rank1;
			else temp[i].rank1 = i;
			stus.push_back(temp[i]);
		}
	}
	sort(stus.begin(), stus.end(), cmp);
	for (int i = 0; i < stus.size(); i++) {
		if (i - 1 >= 0 && stus[i].score == stus[i - 1].score) stus[i].rank2 = stus[i - 1].rank2;
		else stus[i].rank2 = i;
	}
	cout << stus.size() << endl;
	for (int i = 0; i < stus.size(); i++) {
		printf("%013ld", stus[i].id);
		cout <<" " << stus[i].rank2+1 << " " << stus[i].pos << " " << stus[i].rank1+1 << endl;
	}
	system("pause");
}
Day50: [PAT甲级]  1025 PAT Ranking (25分)Day50: [PAT甲级]  1025 PAT Ranking (25分) qq2215459786 发布了49 篇原创文章 · 获赞 13 · 访问量 415 私信 关注
上一篇:2020 2.4


下一篇:1025 PAT Ranking (25 分)