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

为什么是Time Limit Exceeded呢?。。

Posted by 18340861521 at 2017-03-20 19:57:50 on Problem 1002
代码:
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

struct dupli{
    string phone;
    int time;
};
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());
    vector<string> List = numberList;
    int ans = unique(List.begin(),List.end())-List.begin();
    int s=List.size();
    for(int i=ans;i<s;i++){
        List.erase(List.begin()+ans);
    }
    bool flag = false;
    for(int i=0;i<List.size();i++){
        int cCount = count(numberList.begin(),numberList.end(),List[i]);
        if(cCount>1){
            cout<<List[i]<<" "<<cCount<<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