束手无策了,输入输出都搞不定QWQ

P5730 【深基5.例10】显示屏

chengyan @ 2023-09-13 20:24:57


import java.util.Scanner;

public class Screen {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        char[] a = new char[10000];
        String[] ans = new String[10];
        for (int i = 1; i <= n; i++) {
            a[i] = scanner.next().charAt(0);
            if (a[i] == '1') {
                ans[1] += "..X.";
                ans[2] += "..X.";
                ans[3] += "..X.";
                ans[4] += "..X.";
                ans[5] += "..X.";
            } else if (a[i] == '2') {
                ans[1] += "XXX.";
                ans[2] += "..X.";
                ans[3] += "XXX.";
                ans[4] += "X...";
                ans[5] += "XXX.";
            } else if (a[i] == '3') {
                ans[1] += "XXX.";
                ans[2] += "..X.";
                ans[3] += "XXX.";
                ans[4] += "..X.";
                ans[5] += "XXX.";
            } else if (a[i] == '4') {
                ans[1] += "X.X.";
                ans[2] += "X.X.";
                ans[3] += "XXX.";
                ans[4] += "..X.";
                ans[5] += "..X.";
            } else if (a[i] == '5') {
                ans[1] += "XXX.";
                ans[2] += "X...";
                ans[3] += "XXX.";
                ans[4] += "..X.";
                ans[5] += "XXX.";
            } else if (a[i] == '6') {
                ans[1] += "XXX.";
                ans[2] += "X...";
                ans[3] += "XXX.";
                ans[4] += "X.X.";
                ans[5] += "XXX.";
            } else if (a[i] == '7') {
                ans[1] += "XXX.";
                ans[2] += "..X.";
                ans[3] += "..X.";
                ans[4] += "..X.";
                ans[5] += "..X.";
            } else if (a[i] == '8') {
                ans[1] += "XXX.";
                ans[2] += "X.X.";
                ans[3] += "XXX.";
                ans[4] += "X.X.";
                ans[5] += "XXX.";
            } else if (a[i] == '9') {
                ans[1] += "XXX.";
                ans[2] += "X.X.";
                ans[3] += "XXX.";
                ans[4] += "..X.";
                ans[5] += "XXX.";
            } else if (a[i] == '0') {
                ans[1] += "XXX.";
                ans[2] += "X.X.";
                ans[3] += "X.X.";
                ans[4] += "X.X.";
                ans[5] += "XXX.";
            }
        }
        for (int i = 1; i <= 5; i++) {
            ans[i] = ans[i].substring(0, ans[i].length() - 1);
            System.out.println(ans[i]);
        }
    }
}

by chengyan @ 2023-09-13 20:28:43

输入端:无法做到在输入一次的情况下将0123456789存储到数组里(正则,字符串转数字都试过,不行),关键是这个只能输入一次,真不会了。 输出端:输出前总是带一个null nullXXX...X.XXX.XXX.X.X.XXX.XXX.XXX.XXX.XXX nullX.X...X...X...X.X.X.X...X.....X.X.X.X.X nullX.X...X.XXX.XXX.XXX.XXX.XXX...X.XXX.XXX nullX.X...X.X.....X...X...X.X.X...X.X.X...X nullXXX...X.XXX.XXX...X.XXX.XXX...X.XXX.XXX

这个思路是我看题解得来的,把c++转成Java来写的,希望有大佬帮我一下,哪里有疑问的@本蒟蒻就好了,马上回复


|