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?ORZ

Posted by Sister at 2010-03-17 21:37:34 on Problem 1580
#include<iostream>
using namespace std;

int gcd(int a,int b)
{
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main()
{
	int i,j,k,len_1,len_2,num,max_1,max_2;
	char a1[201],a2[201];
	while(scanf("%s",a1)!=EOF)
	{
		if(!strcmp(a1,"-1")) break;
		max_1=0;max_2=0;
		scanf("%s",a2);
		len_1=strlen(a1);
		len_2=strlen(a2);
		for(k=0;k<len_1;k++)
		{
			num=0;
			for(i=k,j=0;i<len_1 && j<len_2;i++,j++)
			{
				if(a1[i]==a2[j]) num++;
			}
			if(num>max_1) max_1=num;
		}
		for(k=0;k<len_2;k++)
		{
			num=0;
			for(i=k,j=0;i<len_1 && j<len_2;i++,j++)
			{
				if(a2[i]==a1[j]) num++;
			}
			if(num>max_2) max_2=num;
		}
		int max=max_1>max_2 ? max_1:max_2;
		int ans=gcd(max*2,len_1+len_2);
		if(max*2==len_1+len_2) printf("appx(%s,%s) = 1\n",a1,a2);
		else if(max==0) printf("appx(%s,%s) = 0\n",a1,a2);
		else printf("appx(%s,%s) = %d/%d\n",a1,a2,max*2/ans,(len_1+len_2)/ans);
	}	
	return 7;
}

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