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

能帮我看看这个代码为什么WA?

Posted by jlnu123 at 2008-10-04 15:36:25 on Problem 2406
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	while(cin>>s && s!=".")
	{
		
		unsigned long i,j,len=s.length();
        bool found=false;
		for(i=1;i<len;++i)
			if(s[0]==s[i])
			{
				found=true;
				break;
			}

		if(!found)
		
			cout<<1<<endl;
		
		
		else
		{
			int count=1;
			string s2;
			s2=s.substr(0,i);
			
			int len2=s2.length();
			string::size_type flag;
		    
			for(j=i;j<len;j=flag+1)
			{
				
                
				flag=s.find(s2,j);
				
			    
				if(flag==string::npos)
				
				      break;
				  
				
				else
						++count;
				
				
			}
          
			cout<<count<<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