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 |
连介绍都过不了的都能过??这题超级FT#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator