NYOJ 204 Coin Test

 地址:http://acm.nyist.net/JudgeOnline/problem.php?pid=204
1
#include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 int main() 5 { 6 int i,N,k,t,m,n,a,b; 7 char s[65536]; 8 scanf("%d",&N); 9 getchar(); 10 gets(s); 11 for(a=b=i=0;i<N;i++) 12 { 13 if(s[i]=='U') 14 a++; 15 if(s[i]=='D') 16 b++; 17 if(s[i]=='S') 18 break; 19 } 20 m=a; 21 n=b+a; 22 while(m!=0) 23 { 24 k=n%m; 25 n=m; 26 m=k; 27 } 28 if(i!=N) 29 printf("Bingo\n"); 30 else if(fabs((float)a/(a+b)-0.5)>0.003) 31 printf("Fail\n"); 32 else 33 printf("%d/%d\n",a/n,(a+b)/n); 34 system("pause"); 35 return 0; 36 }

你可能感兴趣的:(test)