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

Re:哪位过的大神把代码贴出来瞧瞧。。。

Posted by smwwh at 2010-07-19 22:42:58 on Problem 3753
In Reply To:哪位过的大神把代码贴出来瞧瞧。。。 Posted by:0911180012 at 2010-01-16 12:21:38
> rt

记住一点就能AC, 当关键字找不到时, 输出整个字符串, 切记切记!!!
#include<iostream>
using namespace std;
int main()
{
	int i, j, keyLen, flag;
	char src[256], key[16];
	while(scanf("%s", src) != EOF)
	{
		while(1)
		{
			flag = 1;
			scanf("%s", key);
			if(!strcmp(key, "END"))
				break;
			else if(!strcmp(key, "NULL"))
			{
				puts("0 NULL");
				continue;
			}
			keyLen = strlen(key);
			for(i=0; i<=strlen(src) - keyLen; i++)
			{
				if(!strncmp(src + i, key, keyLen))
				{
					if(i == 0)
						puts("0 NULL");
					else
					{
						printf("%d ", i);
						for(j=0; j<i; j++)
							putchar(src[j]);
						printf("\n");
					}
					flag = 0;
					break;
				}
			}
			if(flag)
				printf("%d %s\n", strlen(src), src);
				//puts("0 NULL");
		}
	}
	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