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 |
总是WA,牛大们帮我看看,谢谢了#include <string> #include <list> #include <iostream> using namespace std; string process(string s); int main() { list<string> lstr;//list store input strings string s; long linenum; //store number of first line getline(cin,s); const char *str=s.c_str(); linenum=atol(str); long i=0; while(i<linenum && getline(cin,s)) //read strings { lstr.push_back(process(s));// function process() is defined bellow ++i; } lstr.sort();//sort strings follow ascending order list<long> llong; list<string> lstr1; list<string>::iterator str_it; for(str_it=lstr.begin();str_it!=lstr.end();)//delet strings which are same and counter { //they number .strings which store in the long l=0; //lstr1.corresponding number store in llong. string s=*str_it; while(str_it!=lstr.end() && s.compare(*str_it)==0) { ++l; str_it=lstr.erase(str_it); } if(l>1) { lstr1.push_back(s); llong.push_back(l); } } list<long>::iterator lon_it; if(llong.empty()) //if llong is empty which means no two same strings cout<<"No duplicates."<<endl; else //output results follow the format { lon_it=llong.begin(); str_it=lstr1.begin(); while(str_it!=lstr1.end() && lon_it!=llong.end()) { cout<<(*str_it).substr(0,3)<<'-'<<(*str_it).substr(3,4)<<' '<<*lon_it<<endl; ++str_it; ++lon_it; } } return 0; } string process(string s) //converts strings to a standard format like 1234567 { char map(char ch); string::iterator it; for(it=s.begin();it!=s.end();) { if(*it=='-') it=s.erase(it); else if(*it>='A' && *it<='Y') { *it=map(*it); ++it; } else ++it; } return s; } char map(char ch)//mapping function { if(ch=='A' || ch=='B' || ch=='C') return '2'; else if(ch=='D' || ch=='E' || ch=='F') return '3'; else if(ch=='G' || ch=='H' || ch=='I') return '4'; else if(ch=='J' || ch=='K' || ch=='L') return '5'; else if(ch=='M' || ch=='N' || ch=='O') return '6'; else if(ch=='P' || ch=='R' || ch=='S') return '7'; else if(ch=='T' || ch=='U' || ch=='V') return '8'; else if(ch=='W' || ch=='X' || ch=='Y') return '9'; else return 'e'; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator