用的笨办法。读进字符串然后解析出来,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;
}