码迷,mamicode.com
首页 > 其他好文 > 详细

Sicily 13980. Record Keeping

时间:2015-04-13 12:59:47      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:sicily

13980. Record Keeping

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Farmer John has been keeping detailed records of his cows as they enter the barn for milking. Each hour, a group of 3 cows enters the barn, and Farmer John writes down their names. For example over a 5-hour period, he might write down the following list, where each row corresponds to a group entering the barn:

BESSIE ELSIE MATILDA
FRAN BESSIE INGRID
BESSIE ELSIE MATILDA
MATILDA INGRID FRAN
ELSIE BESSIE MATILDA

Farmer John notes that the same group of cows may appear several times on his list; in the example above, the group of BESSIE, ELSIE, and MATILDA appears three times (even though Farmer John didn‘t necessarily write their names in the same order every time they entered the barn).

Please help Farmer John count the number of occurrences of the group entering the barn the most.

Input

* Line 1: The number of hours, N, for which Farmer John keeps records (1 <= N <= 1000).

* Lines 2..1+N: Each line contains a list of three space-separated cow names. Each name is between 1 and 10 characters and uses only the letters A-Z.

Output

* Line 1: The number of occurrences of the group entering the barn the most often.

Sample Input

5
BESSIE ELSIE MATILDA
FRAN BESSIE INGRID
BESSIE ELSIE MATILDA
MATILDA INGRID FRAN
ELSIE BESSIE MATILDA

Sample Output

3

Hint

In the sample, the group {BESSIE, ELSIE, MATILDA} enters the barn on three separate occasions.

Problem Source

2015年每周一赛第六场

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

int main() {
	std::ios::sync_with_stdio(false);

	int n;
	cin >> n;
	map<string, int> m;
	while (n--) {
		vector<string> v(3);
		for (int i = 0; i < 3; i++) cin >> v[i];
		sort(v.begin(), v.end());
		string s;
		for (int i = 0; i < 3; i++) s += v[i];
		map<string, int>::iterator iter = m.find(s);
		if (iter == m.end()) m[s] = 1;
		else iter->second++;
	}
	int ans = 0;
	for (map<string, int>::iterator iter = m.begin(); iter != m.end(); iter++) {
		if (iter->second > ans) ans = iter->second;
	}
	cout << ans << endl;

	return 0;
}

Sicily 13980. Record Keeping

标签:sicily

原文地址:http://blog.csdn.net/u012925008/article/details/45022999

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!