Problem Statement | |||||||||||||
Exactly one million contestants, numbered 1 through 1,000,000, took part in a programming contest. The rules of the contest are simple: the winner is the contestant who solves the largest number of tasks. If there are more contestants tied for most tasks solved, the winner is the one who was the first to have all of their tasks solved. During the contest the judges were keeping a log of all accepted solutions. You are given this log as a vector <int> events. The i-th element of events is the number of the contestant who submitted the i-th accepted solution (both indices are 0-based). For example, if events = {4, 7, 4, 1}, this is what happened during the contest:
Compute and return the number of the contestant who won the contest. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Constraints | |||||||||||||
- | events will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element of events will be between 1 and 1,000,000, inclusive. | ||||||||||||
Examples | |||||||||||||
0) | |||||||||||||
| |||||||||||||
1) | |||||||||||||
| |||||||||||||
2) | |||||||||||||
| |||||||||||||
3) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
这个简单的!!
#include<math.h>
#include <cmath>
#include<sstream>
#include<vector>
#include <iostream>
#include <functional>
#include <numeric>
#include<map>
#include <string.h>
#include<stdlib.h>
int h[1000000];
using namespace std;
vector<int > permutation;
class ContestWinner{
public:
int getWinner(vector <int> events){
int w=0;
string s;
for(int i=0;i<events.size ();i++ ){
char str[10];
_itoa_s(events[i],str,10);
s+=str;
s+=' ';
}
istringstream iss(s);
for(int i=0;i<events.size ();i++ ){
int t;
iss>>t;
h[t]++;
if(h[w]<h[t])
w=t;
}
return w;
}
};