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

找到bug了,直接用find函数找后缀出的问题...wa了十多次,最后加一个‘r’就AC了

Posted by qiqilrq at 2007-05-16 09:53:04 on Problem 2803
In Reply To:给我一个WA的理由!!!! Posted by:qiqilrq at 2007-05-15 14:07:43
> Source
> 
> Problem Id:2803  User Id:qiqilrq 
> Memory:208K  Time:0MS
> Language:G++  Result:Wrong Answer
> 
> Source 
> 
> //string manipulate
> #include <iostream>
> #include <map>
> #include <string>
> using namespace std;
> 
> const string P[2][5]={{"anti", "post", "pre", "re", "un"},
>                 {"against *", "after *", "before *", "* again", "not *"}
>                };
> const string S[2][5]={{"er","ing","ize","s","tion"},
>                 {"one who *s", "to actively *", "change into *","multiple instances of *","the process of *ing"}    
>                };
> 
> void printsuf(string s){
>     int si;
> 	for(si=0; si<5; ++si)
> 	{
>         int p = s.find(S[0][si]);
> 		if(p>=0 && p == s.length() - S[0][si].length())
> 		{
> 			// cut off the suffix
> 			string ss(&s[0], &s[p]);
> 			string ps = S[1][si];
> 			for(int i=0; i<ps.length(); i++)
> 			{
> 				if(ps[i]=='*')
> 					cout<<ss;
> 				else
> 					cout<<ps[i];
> 			}
> 			return ;
> 		}
> 	}
> 	cout<<s;
> }
> 
> void print(string s){
> 	int pi;
> 	for(pi=0; pi<5; ++pi)
> 	{
> 		if(s.find(P[0][pi]) == 0)
> 		{
> 			// cut off the prefix
> 			string ss = &s[P[0][pi].length()];
> 			string ps = P[1][pi];			
> 			for(int i = 0; i<ps.length(); i++)
> 			{
> 				if(ps[i]=='*')
> 					printsuf(ss);
> 				else
> 					cout<<ps[i];
> 			}
> 			return ;
> 		}
> 	}
> 	printsuf(s);
> }
> 
> int main()
> {
> 	int n;
> 	string str;
> 	cin>>n;
> 	while(n--){
> 		cin>>str;
> 		print(str);
> 		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