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

楼上几位哥们不好意思。我贴一个我用string过的代码。^_^

Posted by 139074241 at 2015-02-01 16:23:57 on Problem 3461
#include<iostream>
#include<string>
using namespace std;
int next[100002];
int mount;
void getNext(string s)
{
	int i=0,j=-1;
	next[0]=-1;
	while(i<s.size())
	{
		if(j==-1||s[i]==s[j])
		{
			++i;
			++j;
			if(s[i]!=s[j])
				next[i]=j;
			else
				next[i]=next[j];
		}
		else
			j=next[j];
	}
}
void match(string w,string t)
{
	int i=0,j=0;
	while(i<t.size())
	{
		if(j==-1||t[i]==w[j])
		{
			i++;
			j++;
		}
		else
			j=next[j];
		if(j==w.size())
		{
			mount++;
			j=next[j];
		}
	}
}
int main()
{
	int t;
	string W,T;
	cin>>t;
	while(t--)
	{
		mount=0;
		cin>>W>>T;
		if(T.size()<W.size())
		{
			cout<<0<<endl;
			continue;
		}
		getNext(W);
		match(W,T);
		cout<<mount<<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