Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

终于A了,之前WA了很久,然后昨晚重新写了一次,今天上午改了差不多两小时吧,终于好了,只能怪实力太差,附上代码

Posted by Pzwjack at 2017-07-05 10:43:44 on Problem 1002
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	map<string,int> mp;
	map<string,int>::iterator mt;
	while (n-- >= 1)
	{
		cin >> s;
		int len = s.length();
		char pn[8];
		int loc = 0;
		for(int i = 0;i < len; i++)
		{
			if (s[i] == '-')
				continue;
			if (s[i]>= 48 && s[i] <= 57)
				pn[loc] = s[i];
			else if (s[i] <= 'P')
				pn[loc] = (s[i] - 'A')/3 + 2 + 48;
			else
			{
				pn[loc] = (s[i] - 'A')/3 + 1 + 48;
				if ((s[i] - 'A')%3)
					pn[loc]++;
			}
			if (loc == 2)
			{
				loc++;
				pn[loc]='-';
			}
			if(loc==7)
				break;
			loc++;
		}
		string str = pn;
		str = str.substr(0,8);
		mt = mp.find(str);
		if(mt != mp.end())
		{
			mt->second++;
		}
		else
		{
			mp.insert(map<string,int>::value_type(str,1));
		}
	}
	bool flag = false;
	for(mt = mp.begin();mt != mp.end(); mt++)
	{
		if(mt->second > 1)
		{
			cout<<mt->first<<' '<<mt->second<<endl;
			flag = true;
		}
	}
	if(!flag)
		cout<<"No duplicates.";
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator