存在一个测试用例不通过,正确率只有91%;
https://www.dotcpp.com/oj/problem1558.html
#include<iostream> #include<stdlib.h> #include<stdio.h> #include<vector> #include<string> #include<math.h> #include<algorithm> #include<cstring> using namespace std; struct color { int cnt = 0; string col; }; vector<color>vec; bool cmp(color a, color b) { if (a.cnt != b.cnt) return a.cnt > b.cnt; else return strcmp(a.col.c_str(),b.col.c_str())<0; } bool charge(string s) { for (int i = 0; i < vec.size(); i++) { if (vec[i].col == s) { vec[i].cnt++; return true; } } return false; } int main(){ int n; cin >> n; getchar(); string s; if (n == 0) return 0; for (int i = 0; i < n; i++) { getline(cin, s); if (!charge(s)) { color c; c.col = s; c.cnt ++; vec.push_back(c); } //cout << s << endl; } sort(vec.begin(), vec.end(), cmp); cout << vec[0].col<<endl; for (int i = 1; i < vec.size(); i++) { if (vec[i].cnt == vec[0].cnt) cout << vec[i].col << endl; } return 0; }