NYOJ286 动物统计

原题链接

简单题。

附ac代码:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	vector<string> vec;
	vector<int> inde;
	string str;
	cin >> n;
	while(n--){
		cin >> str;
		vector<string>::iterator fin;
		fin = find(vec.begin(), vec.end(), str);
		if(fin != vec.end()) 
			++inde[fin - vec.begin()];
		else{
			vec.push_back(str);
			inde.push_back(1);			
		}
	}
	//找到最大值
	vector<int>::iterator ite = max_element(inde.begin(), inde.end());
	cout << vec[ite - inde.begin()]
		 << ' ' << *ite << endl;
	return 0;
}


posted on 2014-02-18 10:11  长木Qiu  阅读(137)  评论(0编辑  收藏  举报