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 |
请教。。请各位仁兄查看,为什么超时?#include <iostream> #include <string> using namespace std; string string_replace(string resource,string re_str,string dis_str) { string abc=resource; abc.replace(&abc[abc.find(re_str)],&abc[abc.find(re_str)]+re_str.size(),dis_str); return abc; } int main() { int i; int number; char a[10][81],b[10][81]; string str1[10],str2[10]; string str; char sentence[256]; char t[3]; while(1) { cin>>number; if(number==0)break; gets(t); i=0; while(number>0) { number--; gets(a[i]); str1[i]=a[i]; gets(b[i]); str2[i]=b[i]; i++; } a[i][0]='\0'; gets(sentence); str=sentence; for(i=0;a[i][0]!='\0';i++) { if(str.find(str1[i])<1000) { str=string_replace(str,str1[i],str2[i]); i=-1; } } for(i=0;i<80;i++) { if(str[i]=='\0')break; cout<<str[i]; } cout<<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