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

poj1002总是超时,谁能帮我看看~

Posted by Quixote_Ren at 2014-07-31 22:39:48
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
    int numcount,i,j,k;
    char stanNum[9];
    cin>>numcount;
    string phonenum;
    map<string,int> PhoneBook;
    map<string,int>:: iterator it;
    bool flag;
    for(i=0;i<numcount;i++)
    {
        cin>>phonenum;
        flag=false;
        k=0;
        for(j=0;phonenum[j]!='\0';j++)
        {
            if(k==3)
                stanNum[k++]='-';
            if(phonenum[j]>='0'&&phonenum[j]<='9')
                stanNum[k++]=phonenum[j];
            if(phonenum[j]>='A'&&phonenum[j]<='C')
                stanNum[k++]='2';
            if(phonenum[j]>='D'&&phonenum[j]<='F')
                stanNum[k++]='3';
            if(phonenum[j]>='G'&&phonenum[j]<='I')
                stanNum[k++]='4';
            if(phonenum[j]>='J'&&phonenum[j]<='L')
                stanNum[k++]='5';
            if(phonenum[j]>='M'&&phonenum[j]<='O')
                stanNum[k++]='6';
            if(phonenum[j]=='P'||phonenum[j]=='R'||phonenum[j]=='S')
                stanNum[k++]='7';
            if(phonenum[j]>='T'&&phonenum[j]<='V')
                stanNum[k++]='8';
            if(phonenum[j]>='W'&&phonenum[j]<='Y')
                stanNum[k++]='9';
        }
        for(it=PhoneBook.begin();it!=PhoneBook.end();it++)
        {
            if(it->first==string(stanNum))
            {
                flag=true;
                it->second++;
                break;
            }
        }
        if(flag==false)
        {
            stanNum[k]='\0';
            PhoneBook[string(stanNum)]=1;
        }
    }
    flag=false;
    for(it=PhoneBook.begin();it!=PhoneBook.end();it++)
    {
        if(it->second>1)
        {
            cout<<it->first<<" "<<it->second<<endl;
            flag=true;
        }

    }
    if(flag==false)
        cout<<"No duplicates"<<endl;
    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