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 |
my answer is correct! but WA!!!#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; typedef struct{ string str; int dup; }str_dup; vector<str_dup> dups; bool dupGrt ( str_dup elem1, str_dup elem2 ) { if(elem1.str.compare(elem2.str)<0) return true; } void add2dups(string dp){ int rep=0; for(unsigned int i=0; i<dups.size(); i++){ if(dups[i].str==dp){ rep++; dups[i].dup++; } } if(rep==0){ str_dup temp; temp.str=dp; temp.dup=0; dups.push_back(temp); } } int main(){ int count=0; cin>>count; string line; vector<string> lines; for(int i=0; i<count; i++){ cin>>line; string l2; for(unsigned int j=0;j<line.size(); j++){ if(line[j]!='-'){ switch(line[j]){ case 'A': case 'B': case 'C': l2.append(1,'2'); break; case 'D': case 'E': case 'F': l2.append(1,'3'); break; case 'G': case 'H': case 'I': l2.append(1,'4'); break; case 'J': case 'K': case 'L': l2.append(1,'5'); break; case 'M': case 'N': case 'O': l2.append(1,'6'); break; case 'P': case 'R': case 'S': l2.append(1,'7'); break; case 'T': case 'U': case 'V': l2.append(1,'8'); break; case 'W': case 'X': case 'Y': l2.append(1,'9'); break; default: l2.append(1,line[j]); } } } l2.insert(3,1,'-'); //cout<<line<<" "<<l2<<endl; add2dups(l2); } sort(dups.begin(),dups.end(),dupGrt); bool noDup=false; for(unsigned int i=0; i<dups.size(); i++){ if(dups[i].dup>0){ cout<<dups[i].str<<' '<<dups[i].dup+1<<endl; noDup=true; } } if(!noDup){ cout<<"No duplicates."<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator