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

连介绍都过不了的都能过??这题超级FT

Posted by yuanyirui at 2007-06-01 11:14:03 on Problem 1580
#include<stdio.h>
#include<math.h>
#include<string.h>
char a[255],b[255];
int gcd(int m,int n)
{
    int f;
    while(n>0)
    {f=m;m=n;n=f%m;}
    if(m<0)m=-m;
    return m;
}    
int main()
{
  //  freopen("in.txt","r",stdin);
  //  freopen("out.txt","w",stdout);
    int j,k,p,x,fd,vmax,vk,an,bn;
    while(scanf("%s",a),strcmp(a,"-1"))
    {
       scanf("%s",b);printf("appx(%s,%s) = ",a,b);
       if(!strcmp(a,b)){printf("1\n");continue;}
       an=strlen(a);bn=strlen(b);
       p=an+bn;x=0;k=0;
       do{
         j=0;vmax=0;vk=k;
         do{
           if (a[vk]==b[j]){vk++;j++;vmax++;}
           else{j++;} 
         }    
         while(j<bn&&vk<an);
         k++;if(vmax>x)x=vmax;
       } 
       while (k<an);
       x=2*x;
       if(x==0)printf("0\n");
       else{
         fd=gcd(x,p);x=x/fd;p=p/fd;
         printf("%d/%d\n",x,p);
       }    
    }
    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