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!
应该没问题,不知你到底要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;
}