坑爹的水题之“元芳你怎么看”
生活随笔
收集整理的这篇文章主要介绍了
坑爹的水题之“元芳你怎么看”
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
题目大意:
一些人分银子,如果每个人分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\n"); 11 else 12 printf ("Back to the adult, it surely has something\n"); 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\n"); 20 else 21 printf ("Back to the adult, it surely has something\n"); 22 } 23 return 0;我也是醉了,这么相似的代码竟然是错的 = =!
转载于:https://www.cnblogs.com/love-fromAtoZ/p/7528272.html
总结
以上是生活随笔为你收集整理的坑爹的水题之“元芳你怎么看”的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: SQL Server-服务器迁移之后lo
- 下一篇: 错误问题