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

哪位大神出来帮忙一下,我都已经没用strrev函数了。。。仍然是编译错误。

Posted by smyyh at 2012-08-17 08:48:36 on Problem 1226
#include <stdio.h>
#include <string.h>
int t, n;
char str[101][101];
void mystrrev(char *s)
{
	int i, length=strlen(s);
	char temp[101];
	for(i=0; i<length; i++)
	{
		temp[i]=s[length-i-1];
	}
	temp[i]='\0';
	strcpy(s,temp);
}

int sm(char *source)
{
	int ss=strlen(source),sl=strlen(source),i,j;
	bool flag=(true,false);
	char substr[101],revstr[101];
	while(ss>0)
	{
		//搜索不同长度的子串,从不同长度开始搜索。
		for(i=0;i<=sl-ss;i++)
		{
			//搜索长度为ss的子串
			strncpy(substr,source+i,ss);//复制字符串中的子串。
			strncpy(revstr,source+i,ss);
			substr[ss]=revstr[ss]='\0';
			mystrrev(revstr);//对字符串进行反序.系统不支持strrev函数,故另设函数
			flag=true;
			for(j=0;j<n;j++)
				if(strstr(str[j],substr)==NULL&&strstr(str[j],revstr)==NULL)//在字符串中寻找子字符串。
				{
					flag=false;
					break;
				}
				if(flag)
					return(ss);
		}
		ss--;
	}
	return 0;
}

void main()
{
	int min,i;
	char ms[101];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		min=100;
		for(i=0;i<n;i++)
		{
			scanf("%s",str[i]);
			if(strlen(str[i])<min)
			{
				//寻找输入字符串中最短的字符串。
				
				strcpy(ms,str[i]);//复制字符串
				min=strlen(ms);
			}
		}
		printf("%d\n",sm(ms));
	}
}

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