编程介的小学生 2019-08-05 21:59 采纳率: 20.5%
浏览 279

是否可以打开盒子的一个判断,怎么采用的C语言,谢谢

Problem Description
One day, winnie received a box and a letter. In the letter, there are three integers and five operations(+,-,*,/,%). If one of the three integers can be calculated by the other two integers using any operations only once.. He can open that mysterious box. Or that box will never be open.

Input
The input contains several test cases.Each test case consists of three non-negative integers.

Output
If winnie can open that box.print "oh,lucky!".else print "what a pity!"

Sample Input
1 2 3

Sample Output
oh,lucky!

  • 写回答

1条回答 默认 最新

  • Rotch 2019-08-05 23:06
    关注

    应该没问题,不知你到底要C语言还是R语言。反正核心算法就是这样判断一下,别想复杂了。

    #include <stdio.h>
    #include <stdlib.h>
    
    int a, b, c;
    
    int main() {
    
        scanf("%d%d%d", &a, &b, &c);
        if ((a + b == c) || (a + c == b) || (b + c == a)) {
            printf("oh,lucky!");
        }
        else if ((a * b == c) || (a * c == b) || (b * c == a)) {
            printf("oh,lucky!");
        }
        else if ((a - b == abs(c)) || (a - c == abs(b)) || (b - c == abs(a))) {
            printf("oh,lucky!");
        }
        else if (((a != 0) && ((c % a == b) || b % a == c)) ||
                 ((b != 0) && ((c % b == a) || a % b == c)) ||
                 ((c != 0) && ((a % c == b) || b % c == a))) {
            printf("oh,lucky!");
        }
        else if (((a != 0) && ((c / a == b) || b / a == c)) ||
                 ((b != 0) && ((c / b == a) || a / b == c)) ||
                 ((c != 0) && ((a / c == b) || b / c == a))) {
            printf("oh,lucky!");
        }
        else {
            printf("what a pity!");
        }
    
        return 0;
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?