Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请教。。请各位仁兄查看,为什么超时?

Posted by a5256869 at 2009-08-05 01:14:10 on Problem 1572
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator