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> gcd(long int a, long int b) { long int t; if(a < b) { t=a; a=b; b=t; } if(a % b == 0) return b; else return gcd(b,a%b); } int main() { long int dis_up,dis_down,gcd; long int k,t,j,i=0; long int mum,son; long int up[1000], down[1000]; struct num { long int num_mum; long int num_son; }Num[100]; while(1) { scanf("%ld%ld",&Num[i].num_mum, &Num[i].num_son); getchar(); if(Num[i].num_mum == 0) break; i++; } for(j=0; j<i; j++) { long int mul_mum=1,mul_son=1; mum=Num[j].num_mum; son=Num[j].num_son; if(son > mum/2) son=mum-son; dis_up=son; dis_down=son; for(k=0; k<dis_up; k++) up[k]=mum--; for(t=0; t<dis_down; t++) down[t]=son--; for(k=0; k<dis_up; k++) for(t=0; t<dis_down; t++) { if(up[k]>down[t]){ gcd=gcl(up[k],down[t]); if(down[t] != 1 && gcd!=1) { up[k]=up[k]/gcd; down[t]=down[t]/gcd; } } } for(k=0; k<dis_up; k++) { mul_mum*=up[k]; up[k]=0; } for(t=0; t<dis_down; t++) { mul_son*=down[t]; down[t]=0;} printf("%ld\n",mul_mum/mul_son); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator