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

刚开始怎么都超时,后来用了map直接A了

Posted by Ramzey at 2016-05-10 21:44:06 on Problem 1002
附个代码
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
char num[300];
map <string,int> ans;
int main(void)
{
	cin.sync_with_stdio(false);
	num['A']=num['B']=num['C']='2';
	num['D']=num['E']=num['F']='3';
	num['G']=num['H']=num['I']='4';
	num['J']=num['K']=num['L']='5';
	num['M']=num['N']=num['O']='6';
	num['P']=num['R']=num['S']='7';
	num['T']=num['U']=num['V']='8';
	num['W']=num['X']=num['Y']='9';
	int t;
	cin>>t;
	while(t--)
	{
		string s,d="";
		int cnt=0;
		cin>>s;
		for(int i=0;i<s.length();i++)
		{
			if(cnt==3)
			{
				d=d+'-';
				cnt++;
			}
			if(s[i]>='A'&&s[i]<='Z')
			{
				d=d+num[s[i]];
				cnt++;
			}
			else if(s[i]>='0'&&s[i]<='9')
			{
				d=d+s[i];
				cnt++;
			}
		}
		ans[d]++;
	}
	int flag=1;
    for(map<string,int>::iterator it=ans.begin();it!=ans.end();it++)
        if((*it).second>1)
        {
            cout<<(*it).first<<" "<<(*it).second<<endl;
            flag=0;
        }
    if(flag)
        printf("No duplicates.\n");
    return 0;
}
//萌新交流q:330860800 = =

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