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

新手————

Posted by 13926491 at 2016-03-04 20:54:58 on Problem 1580 and last updated at 2016-03-04 20:59:36
#include<stdio.h>
#include<string.h>

int mod(int n,int m)
{
	while(n<0)n+=m;
	      return n%m;
	  }

int gcd(int a,int b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}

void pint(int x,int y)
{
	if(x==0)
	{
		printf("0\n");
		return ;
	}
    if(x==y)
    {
    	printf("1\n");
    	return ;
    }
    printf("%d/%d\n",x/gcd(y,x),y/gcd(y,x));
    return ;
}

int main()
{
    char a[100]={0},b[100]={0};
	while(scanf("%s",a)!=EOF)
	{
	     if(a[0]=='-'&&a[1]=='1')break;
	     scanf("%s",b);
		 
		 int n=strlen(a);
		 int m=strlen(b);
		 int max=0;
		 int i,q,w,l;
		 for(i=0;i<=m-1;i++)
		 {
		 	int sum=0;
		 	for(q=0;q<=n-1;q++)
		 	{
		 		if(a[q]==b[mod(q+i,m)])sum+=1;
		 	}
		 	if(sum>max)max=sum;
		 }
		 printf("appx(%s,%s) = ",a,b);
		 pint(max*2,n+m);
		 
		 for(i=0;i<=99;i++)
		 {
		 	a[i]=b[i]='\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