用的笨办法。读进字符串然后解析出来,A了。 #include <vector> #include <iostream> #include <string> #include <sstream> #include <map> using namespace std;  struct Person {     int vote;      int count;  }; void fill(vector<int>& v, string s) {     string sub;     for (int i = 0; i < s.size(); )     {         int j = i;          if (s[i] >= '0' && s[i] <= '9')         {             while (s[j] >= '0' && s[j] <= '9') j++;             sub = s.substr(i, j - i);              stringstream str(sub);             int num;             str >> num;             v.push_back(num);         }         i = j + 1;      } } int main() {     string vstr;      string wstr;     getline(cin, vstr);     getline(cin, wstr);     vector<int> v;     fill(v, vstr);     vector<int> w;     fill(w, wstr);     map<int, Person> votes;      for (int i = 0; i < v.size(); i++)     {         votes[v[i]].count++;          votes[v[i]].vote += w[i];      }     map<int, Person>::iterator person = votes.begin();     for(map<int, Person>::iterator it = votes.begin(); it != votes.end(); it++)     {         if (person->second.vote < it->second.vote)             person = it;          if (person->second.vote == it->second.vote && person->second.count < it->second.count)             person = it;      }     cout << person->first << endl; }
点赞 评论

相关推荐

08-29 16:36
门头沟学院 Java
嗨害嗨我来了:疑似连续加班后点了个拼好饭发现优惠券更便宜后晕倒的幻觉罢了
点赞 评论 收藏
分享
Peach33:项目的 “完整度”“你的思考深度” 和 “能匹配岗位的基础能力”,远比 “复杂度” 更重要。
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务