Skip to content

L1-062 幸运彩票

彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。

输入格式:

输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。

输出格式:

对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.

输入样例:

tex
2
233008
123456
2
233008
123456

输出样例:

tex
You are lucky!
Wish you good luck.
You are lucky!
Wish you good luck.

Solution:

java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char[] chars = in.readLine().toCharArray();
            int left = 0, right = 0;
            for (int j = 0; j < 3; j++) {
                left += chars[j] - '0';
                right += chars[5 - j] - '0';
            }
            if (i > 0) sb.append("\n");
            if (left == right) sb.append("You are lucky!");
            else sb.append("Wish you good luck.");
        }
        System.out.println(sb);
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char[] chars = in.readLine().toCharArray();
            int left = 0, right = 0;
            for (int j = 0; j < 3; j++) {
                left += chars[j] - '0';
                right += chars[5 - j] - '0';
            }
            if (i > 0) sb.append("\n");
            if (left == right) sb.append("You are lucky!");
            else sb.append("Wish you good luck.");
        }
        System.out.println(sb);
    }
}

Released under the MIT License.