题目大意:
一些人分银子,如果每个人分x两,那么还有y两分不出去;如果每个人分i 两的话那么还差 j 两银子。问你输入x,y,i,j 四个整数,能否成立。
解题思路:
啥叫思路,我已经WA了5发,还是看不出哪里错了,就特么很尴尬。
题目链接:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1800
AC代码:
1 #include <stdio.h> 2 int main() 3 { 4 double x, y, i, j; 5 while(scanf("%lf%lf%lf%lf",&x,&y,&i,&j)!=EOF) 6 { 7 double n=(y+j)/(i-x); 8 double m=n-(int)n; 9 if (n>0 && m==0) 10 printf ("He is right "); 11 else 12 printf ("Back to the adult, it surely has something "); 13 } 14 return 0; 15 }
我的代码:
1 #include <stdio.h> 2 int main() 3 { 4 int x, y, i, j; 5 while(scanf("%d%d%d%d",&x,&y,&i,&j)!=EOF) 6 { 7 int flag = 1; 8 double p = -1.0; 9 if((i - x) == 0) 10 { 11 flag = 0; 12 } 13 else 14 { 15 p = 1.0 *((y+j)/(i-x)); 16 } 17 double t = p - (int)p; 18 if (p > 0 && t == 0.0 && flag == 1) 19 printf ("He is right "); 20 else 21 printf ("Back to the adult, it surely has something "); 22 } 23 return 0;
我也是醉了,这么相似的代码竟然是错的 = =!