| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
新手————#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator