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:N人帮着看看,strstr函数能用不?

Posted by ctzsm at 2010-01-17 21:59:59 on Problem 3753
In Reply To:N人帮着看看,strstr函数能用不? Posted by:0911130045 at 2010-01-16 13:23:16
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> 
> int SafeStrCpy2KeyWord(char * dest, char * source,int size,char* key)
> {
> 	if(strcmp(key,"NULL") == 0)
> 	{
> 		strcpy(source,"NULL");
> 		return 0;
> 	}
> 
> 
> 	char * p=strstr(dest,key);
> 	int n=p-dest;
> 	if(n==0)
> 	{
> 		strcpy(source,dest);
> 		return 0;
> 	}
> 	strncpy(source,dest,n);
> 	source[n]='\0';
> 	return n;
> }
> int main()
> {
> 	char dest[256],key[256],source[256];
> 	while(scanf("%s",dest)!=EOF)
> 	{
> 		int size=strlen(dest);
> 		scanf("%s",key);
> 		while(strcmp(key,"END")!=0)
> 		{
> 			int len=SafeStrCpy2KeyWord(dest,source,size,key);
> 			printf("%d %s\n",len,source);
> 			scanf("%s",key);
> 		}
> 	}
> 	return 0;
> }
能用strstr,我就是用的那个,AC了的

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