Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
大家帮我看看啊,老是wrong Answer啊我自己试过很多次都没找到哪错了? #include<iostream> #include<string> #include<vector> using namespace std; //quick sort void QuickSort(vector<string>&pData, int left, int right) { int i, j; string middle, iTemp; i = left; j = right; middle = pData[(left + right) / 2]; do { while ((pData[i] < middle) && (i < right)) i++; while ((pData[j] > middle) && (j > left)) j--; if (i <= j) { iTemp = pData[i]; pData[i] = pData[j]; pData[j] = iTemp; i++; j--; } } while (i <= j) ; if(left<j) QuickSort (pData,left,j); if(right>i) QuickSort (pData,i,right); } int main() { string str; vector<string>svec; int tele_num=0; //input the number of telephone numbers cin>>tele_num; //input the telephone numbers for(int i=0;i!=tele_num;i++){ cin>>str; svec.push_back(str); } //change the telephone number into the standard form for(vector<string>::size_type index=0;index!=tele_num;index++){ string::size_type pos=0; str=""; while((pos=svec[index].find_first_not_of('-',pos))!=string::npos){ if(svec[index][pos]>=65&&svec[index][pos]<=90){ switch(svec[index][pos]){ case 'A': case 'B': case 'C': str.append("2"); break; case 'D': case 'E': case 'F': str.append("3"); break; case 'G': case 'H': case 'I': str.append("4"); break; case 'J': case 'K': case 'L': str.append("5"); break; case 'M': case 'N': case 'O': str.append("6"); break; case 'P': case 'R': case 'S': str.append("7"); break; case 'T': case 'U': case 'V': str.append("8"); break; case 'W': case 'X': case 'Y': str.append("9"); break; default: break; } } else str.append(1,svec[index][pos]); ++pos; } str.insert(3,1,'-'); svec[index]=str; } //sort the input QuickSort(svec,0,tele_num-1); //print the output string prestr=svec[0]; int num=0; bool alldiffer=true; for(vector<string>::iterator vit=svec.begin();vit!=svec.end();vit++){ if(prestr==*vit){ ++num; } else { if(num>1){ cout<<prestr<<ends<<num<<endl; alldiffer=false; } num=1; } if(vit==svec.end()-1&&num>1){ cout<<prestr<<ends<<num; alldiffer=false; } prestr=*vit; } if(alldiffer) cout<<"No duplicates."; return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator