国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1025. PAT Ranking (25)

2019-11-11 02:38:10
字體:
來源:轉載
供稿:網友

一道水題,vector存儲學生,每輸入一個地方的學生,放入臨時的vector中,并進行排序,設置好地方排名,然后都放入總的一個vector中,最后對總的vector進行sort,注意sort的時候如果成績一樣,按id的順序排,設置好總排名,輸出即可

#include<iostream>#include<vector>#include<string>#include<algorithm>using namespace std;typedef struct student{ string id; int grade; int final_rank; int location_num; int local_rank;}stu;bool compare(stu s1, stu s2){ if (s1.grade > s2.grade || (s1.grade == s2.grade && s1.id.compare(s2.id) < 0)) return true; else return false;}int main(){ vector<stu> all; int N; cin >> N; for (int t = 1;t <= N;t++) { stu temp_stu; vector<stu> temp_vec; int K; cin >> K; for (int i = 0;i < K;i++) { temp_stu.location_num = t; string str; int g; cin >> str >> g; temp_stu.id = str; temp_stu.grade = g; temp_vec.push_back(temp_stu); } sort(temp_vec.begin(), temp_vec.end(), compare); temp_vec[0].local_rank = 1; for (int i = 2;i <= temp_vec.size();i++) if (temp_vec[i - 1].grade == temp_vec[i - 2].grade) temp_vec[i - 1].local_rank = temp_vec[i - 2].local_rank; else temp_vec[i - 1].local_rank = i; all.insert(all.end(), temp_vec.begin(), temp_vec.end()); } sort(all.begin(), all.end(), compare); all[0].final_rank = 1; for (int i = 2;i <= all.size();i++) if (all[i - 1].grade == all[i - 2].grade) all[i - 1].final_rank = all[i - 2].final_rank; else all[i - 1].final_rank = i; cout << all.size() << endl; for (auto x : all) cout << x.id << " " << x.final_rank << " " << x.location_num << " " << x.local_rank << endl;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东乡县| 镇安县| 曲阳县| 株洲县| 合江县| 揭东县| 莱西市| 黎川县| 台南县| 阿鲁科尔沁旗| 黄石市| 双江| 中阳县| 磴口县| 泗阳县| 万荣县| 济阳县| 双辽市| 达日县| 盐池县| 英山县| 青田县| 岳普湖县| 阿拉善右旗| 吉林省| 大竹县| 凭祥市| 大厂| 肃宁县| 上高县| 钟山县| 诸暨市| 静乐县| 长岭县| 伊川县| 吉林市| 延津县| 三穗县| 鞍山市| 长沙县| 新疆|