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

WA了的,进来(原因+代码)

Posted by speedcell4 at 2011-05-08 15:12:18 on Problem 1002
问题是在,如果没有重复的,要cout<<"No duplicates."<<endl;
你懂的……
用MAP搞的,貌似比较耗时
#include<iostream>
#include<string>
#include<map>
using namespace std;
int n;
char mapto(char a)
{
    if(a=='0') return '0';
    if(a=='1') return '1';
    if(a=='A'||a=='B'||a=='C'||a=='2') return '2';
    if(a=='D'||a=='E'||a=='F'||a=='3') return '3';
    if(a=='G'||a=='H'||a=='I'||a=='4') return '4';
    if(a=='J'||a=='K'||a=='L'||a=='5') return '5';
    if(a=='M'||a=='N'||a=='O'||a=='6') return '6';
    if(a=='P'||a=='R'||a=='S'||a=='7') return '7';
    if(a=='T'||a=='U'||a=='V'||a=='8') return '8';
    if(a=='W'||a=='X'||a=='Y'||a=='9') return '9';
}
int main()
{
    map<string,int>    now;
    map<string,int> :: iterator inow;
    cin>>n;for(int ii=0;n-ii;ii++)
    {
        string a,b;
        cin>>a;
        int l=a.length();
        for(int i=0,j=0;l-i;i++)
        {
            if(j==3)
            {
                b+='-';
                j++;
            }
            if(a[i]!='-'&&a[i]!='Q'&&a[i]!='Z')
            {
                b+=mapto(a[i]);
                j++;
            }
        }
        inow=now.find(b);
        if(inow==now.end())
        {
            now[b]=1;
        }
        else
        {
            inow->second++;
        }
    }
    int count=0;
    for(inow=now.begin();inow!=now.end();inow++)
    {
        if(inow->second>1)
        {
            count++;
            cout<<inow->first<<" "<<inow->second<<endl;
        }
    }
    if(count==0) cout<<"No duplicates."<<endl;
  //  system("pause");
}

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