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

Re:为什么是Time Limit Exceeded呢?。。

Posted by 18340861521 at 2017-03-22 00:30:32 on Problem 1002
In Reply To:为什么是Time Limit Exceeded呢?。。 Posted by:18340861521 at 2017-03-20 19:57:50
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

string clearNumber(string str){
    int j=0;
    int leng = str.length();
    for(int i=0;i<leng;i++){
        if(str[j]=='-'){
            str.erase(j,1);
            j--;
        }
        j++;
    }
    map<char,char> M;
    M['A']='2';M['B']='2';M['C']='2';M['D']='3';M['E']='3';M['F']='3';M['G']='4';M['H']='4';M['I']='4';M['J']='5';M['K']='5';M['L']='5';
    M['M']='6';M['N']='6';M['O']='6';M['P']='7';M['R']='7';M['S']='7';M['T']='8';M['U']='8';M['V']='8';M['W']='9';M['X']='9';M['Y']='9';
    for(int i=0;i<7;i++){
        if(str[i]>='A'&&str[i]<='Y'&&str[i]!='Q'){
            str[i]=M[str[i]];
        }
    }
    str.insert(3,"-");
    return str;
}


int main(){
    int item;
    cin>>item;
    string phoneNumber;
    vector<string> numberList;
    for(int i=0;i<item;i++){
        cin>>phoneNumber;
        phoneNumber=clearNumber(phoneNumber);
            numberList.push_back(phoneNumber);
    }
    sort(numberList.begin(),numberList.end());
    int number=1;
    bool flag=false;
    for(int i=0;i<numberList.size();i++){
        if(i==numberList.size()-1){
            if(number>1){
                cout<<numberList[i]<<" "<<number<<endl;
                flag=true;
            }
            break;
        }

        if(numberList[i]==numberList[i+1]){
            number++;
        }else{
            if(number>1){
                cout<<numberList[i]<<" "<<number<<endl;
                flag=true;
                number=1;
            }
        }
    }
    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