PAT (Advanced) 1025. PAT Ranking (25)
2014-03-02 16:21
435 查看
水题一个,但是因为排序规则看得不够仔细,有个6分测试点始终通不过,耗费了大量时间,悲剧
。以下完整AC代码:
。以下完整AC代码:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; struct Testee { string id; int score; int location_num; int loca_rank; int final_rank; }; vector<Testee> testee_final; vector<Testee> testee_local; bool cmp(const Testee &a, const Testee &b) { if (a.score != b.score) return a.score > b.score; else return a.id < b.id; } int main() { int n; cin >> n; int tot = 0; for (int i = 0; i < n; i++) { int k; cin >> k; tot += k; Testee tmp; testee_local.clear(); for (int j = 0; j < k; j++) { cin >> tmp.id >> tmp.score; tmp.location_num = i; testee_local.push_back(tmp); } sort(testee_local.begin(), testee_local.end(), cmp); testee_local[0].loca_rank = 0; for (int i = 0; i < k - 1; i++) { if (testee_local[i + 1].score == testee_local[i].score) testee_local[i + 1].loca_rank = testee_local[i].loca_rank; else testee_local[i + 1].loca_rank = i + 1; } for (int j = 0; j < k; j++) { tmp = testee_local[j]; testee_final.push_back(tmp); } } sort(testee_final.begin(), testee_final.end(), cmp); testee_final[0].final_rank = 0; for (int i = 0; i < tot - 1; i++) { if (testee_final[i + 1].score == testee_final[i].score) testee_final[i + 1].final_rank = testee_final[i].final_rank; else testee_final[i + 1].final_rank = i + 1; } cout << tot << endl; for (int i = 0; i < tot; i++) { cout << testee_final[i].id << " " << testee_final[i].final_rank + 1 << " " << testee_final[i].location_num + 1 << " " << testee_final[i].loca_rank + 1 << endl; } return 0; }
相关文章推荐
- PAT (Advanced Level)1025. PAT Ranking (25) 运算符的重载 vector struct
- 【PAT Advanced Level】1025. PAT Ranking (25)
- PAT (Advanced Level) 1025. PAT Ranking (25) 结构体排序
- 1025. PAT Ranking (25)【排序】——PAT (Advanced Level) Practise
- 【PAT】【Advanced Level】1025. PAT Ranking (25)
- PAT (Advanced) 1025. PAT Ranking (25)
- PAT (Advanced Level) Practise 1025. PAT Ranking (25)
- 1025. PAT Ranking (25) @ PAT (Advanced Level) Practise
- PAT (Advanced Level) Practise 1025 PAT Ranking (25)
- PAT (Advanced Level) 1025. PAT Ranking (25)
- 【C++】PAT(advanced level)1025. PAT Ranking (25)*
- PAT (Advanced Level) Practise 1025 PAT Ranking (25)
- 浙大 PAT Advanced level 1025. PAT Ranking (25)
- PAT(甲级)1025. PAT Ranking (25)
- PAT - 甲级 - 1025. PAT Ranking (25)(排序)
- 1025. PAT Ranking (25)
- PAT甲级 1025. PAT Ranking (25)
- PAT 1025. PAT Ranking (25)
- PAT 1025. PAT Ranking (25)
- PAT 1025. PAT Ranking (25)