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

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

1025. PAT Ranking (25)

2019-11-11 03:52:04
字體:
來源:轉載
供稿:網友

一道水題,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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赤水市| 饶阳县| 扎囊县| 思南县| 腾冲县| 祁门县| 马尔康县| 襄城县| 巴南区| 汉阴县| 磴口县| 革吉县| 临沂市| 贡嘎县| 桑日县| 闵行区| 高雄市| 色达县| 上饶市| 涡阳县| 麟游县| 天津市| 万全县| 江永县| 甘孜| 池州市| 海林市| 桓台县| 镇康县| 晋江市| 井冈山市| 崇义县| 石城县| 博客| 荃湾区| 舞钢市| 仁寿县| 中西区| 宣化县| 酉阳| 泽州县|