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 |
跪求解决方法这是我写的程序,其中运用到stl的list和一个排序算法的算法,可是老是出现runtime error 哪位高手指点一下小弟是什么原因啊!!!! 小弟在这先谢谢各位了!!!!!!!!!!!!!!!!!!!!! #include<iostream> #include<list> #include<algorithm> #include<string> using namespace std; class Number { public: Number(string str) { telephone_num=str;//电话号码 total=1;//相同电话号码的个数 } void Translate(); bool operator()(Number&num) { if(telephone_num==num.telephone_num) return true; else return false; } friend bool operator<(Number&num1,Number&num2) { return num1.telephone_num<num2.telephone_num; } void Increase() { total++; } int Return() { return total; } void show() { cout<<telephone_num<<" "<<total<<endl; } private: string telephone_num; int total; }; void Number::Translate()//翻译号码 { string L="";//纪录初步翻译后的电话号码 string M="";//记录最终反以后的电话号码 int j=0;//纪录翻译数据的个数 for(int i=0;i<telephone_num.length();i++) { switch(telephone_num[i]) { case 'A': case 'B': case 'C': L+="2"; break; case 'D': case 'E': case 'F': L+="3"; break; case 'G': case 'H': case 'I': L+="4"; break; case 'J': case 'K': case 'L': L+="5"; break; case 'M': case 'N': case 'O': L+="6"; break; case 'P': case 'R': case 'S': L+="7"; break; case 'T': case 'U': case 'V': L+="8"; break; case 'W': case 'X': case 'Y': L+="9"; break; default: L+=telephone_num[i]; break; } } for(i=0;i<L.length();i++) { if(j==3) { M+="-"; j=-100; } if(L[i]!='-') { M+=L[i]; j++; } } telephone_num=M; } void main() { list<Number> mylist; int number; cin>>number; string Num[100]; for(int i=0;i<number;i++) { cin>>Num[i]; Number mynum(Num[i]); mynum.Translate(); list<Number>::iterator p=mylist.begin(); p=find_if(mylist.begin(),mylist.end(),mynum); if(p!=mylist.end()) { p->Increase(); } else mylist.push_back(mynum); } mylist.sort(); list<Number>::iterator q=mylist.begin(); while(q!=mylist.end()) { if(q->Return()>1) q->show(); q++; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator