zoukankan      html  css  js  c++  java
  • 坑爹的水题之“元芳你怎么看”

    题目大意:

      一些人分银子,如果每个人分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;

    我也是醉了,这么相似的代码竟然是错的 =  =!

  • 相关阅读:
    Http学习(一)
    Android Studio 创建aar包与引用
    C语言模块化编译介绍
    程序结构和分支语句介绍
    数据类型、常量、变量、printf、scanf和运算符
    第一个C语言程序
    Xcode相关整理
    Java: IO 学习小结
    Java: RandomAccessFile
    Java: IO 字符流
  • 原文地址:https://www.cnblogs.com/love-fromAtoZ/p/7528272.html
Copyright © 2011-2022 走看看