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 |
why I still WA(with the source)#include<stdio.h> #include<math.h> int lcd(int a,int b) { int c; while(b!=0) { c=b; b=a%b; a=c; } return a; } int main() { int n[100],m[100],i,j,num,key,flag=0,k,size; double clj,a,c,d; for(i=0;;i++) if(scanf("%d%d",&n[i],&m[i])==EOF) break; size=i; for(k=0;k<size;k++) { clj=10; c=n[k]*1.0/m[k]; for(i=1;i<=m[k];i++) { a=clj; num=(int)(i*n[k]/m[k]); key=num; for(j=0;j<=1;j++) { d=(num+j)*1.0/i; if(fabs(c-d)<a&&lcd(num+j,i)==1) { key=num+j; a=fabs(c-d); } } if(a<clj) { clj=a; printf("%d/%d\n",key,i); } } if(k!=size-1) printf("\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator