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

这或许是最简单的C++ code了,没用任何复杂的数据结构和算法。。

Posted by zhanggt1994 at 2017-05-04 17:51:31 on Problem 1816
int n,m;
char p[100002][8],ss[22];
bool ismatch(char pt[],char s[])
{
	int n1=strlen(pt),n2=strlen(s),i=0,j=0,imatch=-1,prej=-1;
	while(i<n2)
	{
		if(j<n1&&pt[j]=='*')
		{
			prej=j++;
			imatch=i;
		}
		else if(j<n1&&(pt[j]==s[i]||pt[j]=='?'))
		{
			i++;
			j++;
		}
		else if(imatch!=-1)
		{
			i=++imatch;
			j=prej;
		}
		else
			return false;
	}
	while(j<n&&pt[j]=='*')
		j++;
	return j==n1;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		scanf("%s",&p[i]);
	while(m--)
	{
		scanf("%s",&ss);
		int flag=0;
		for(int i=0;i<n;i++)
		{
			if(ismatch(p[i],ss))
			{
				printf("%d ",i);
				flag=1;
			}
		}
		if(flag)
			printf("\n");
		else
			printf("Not match\n");
	}
	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