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 |
跪求,为什么WA?#include<stdio.h> #include <string.h> int yueshu(int m,int n); int main() { char s[100],t[100];/*存放字符串*/ int a[1000];/*记下每次循环相同元素的个数*/ int i=0,j,k,r=0; int m,n; while (scanf("%s", &s) && strcmp(s,"-1") && scanf("%s", &t)) { m=strlen(s); n=strlen(t); r=0; if(m<=n) { for(i=0;s[i]&&t[i];i++) { k=i; a[r]=0; for(j=0;s[j]&&t[j];j++) { if(s[j]==t[k++]) a[r]++; } r++; } i=0; } else { for(i=0;s[i]&&t[i];i++) { k=i; a[r]=0; for(j=0;s[j]&&t[j];j++) { if(t[j]==s[k++]) a[r]++; } r++; } i=0; } for(j=0;j<r;j++) { if(a[i]<a[j]) i=j; } if(a[i]==0) printf("appx(%s,%s) = %d\n",s,t,0); else if(m==n&&m==1&&a[i]==1) printf("appx(%s,%s) = %d\n",s,t,1); else { r=yueshu(2*a[i],m+n); printf("appx(%s,%s) = %d/%d\n",s,t,2*a[i]/r,(m+n)/r); } } return 0; } /*最大公约数*/ int yueshu(int m,int n) { int i,j; if(m<n) { i=m; m=n; n=i; } for(i=0;i<n/2;i++) { if(m%n!=0) { j=m%n; m=n; n=j; } else break; } return n; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator