彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。
输入格式:
输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。
输出格式:
对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!
;否则输出 Wish you good luck.
。
输入样例:
2
233008
123456
结尾无空行
输出样例:
You are lucky!
Wish you good luck.
结尾无空行
真没啥难度啊
代码奉上:
C语言:
#include <stdio.h>
int main() {
int n, x, j, left, right;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
j = right = left = 0;
scanf("%d", &x);
while (x != 0) {
j++;
if (j <= 3) {
right += x % 10;
x /= 10;
} else {
left += x % 10;
x /= 10;
}
}
if (left == right)
printf("You are lucky!\n");
else
printf("Wish you good luck.\n");
}
return 0;
}
C++:
#include <iostream>
using namespace std;
int main() {
int n, x, j, left, right;
cin >> n;
for (int i = 0; i < n; i++) {
j = right = left = 0;
cin >> x;
while (x != 0) {
j++;
if (j <= 3) {
right += x % 10;
x /= 10;
} else {
left += x % 10;
x /= 10;
}
}
if (left == right)
cout << "You are lucky!" << endl;
else
cout << "Wish you good luck." << endl;
}
return 0;
}