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

各位大神帮忙看看,怎么总是WA呀

Posted by peter0211 at 2013-03-23 16:28:09 on Problem 1580
#include<stdio.h>
#include<string.h>
int appx(char *str1,char *str2)
{
	int max,i,j,k,count;
	max = 0;
	for(i = 0;i<(int)strlen(str1);i++)
	{
		count = 0;
		for(j = 0,k = i;j<=(int)strlen(str1)-1-i&&str2[j]!='\0';j++,k++)
		{
			if(str1[k] == str2[j]){count++;}
		}
		if(count>max){max = count;}
	}
	for(i = 0;i<(int)strlen(str2);i++)
	{
		count = 0;
		for(j = 0,k = i;j<=(int)strlen(str2)-1-i&&str1[j]!='\0';j++,k++)
		{
			if(str2[k] == str1[j]){count++;}
		}
		if(count>max){max = count;}
	}
	return max;
}
void simple(int a,int b)
{
	int i,flag;
	flag = 1;
	while(flag)
	{
		i = 2;
		flag = 0;
		if(a%i == 0 && b%i == 0)
		{
			flag = 1;
			a /= i;
			b /= i;
		}
		i++;
	}
	printf("%d/%d\n",a,b);
}
int main()
{
	char str1[20],str2[20];
	int max,length;
	while (scanf("%s", &str1) && strcmp(str1,"-1") && scanf("%s", &str2))
	{
		printf("appx(%s,%s) = ",str1,str2);
		length = strlen(str1)+strlen(str2);
		max = appx(str1,str2);
		max *= 2;
		if(max == 0){printf("0\n");}
		else if(max == length){printf("1\n");}
		else{simple(max,length);}
	}
	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