2020年联通软件研究院校招笔试第一题

2020年联通软件研究院校招笔试第一题_第1张图片2020年联通软件研究院校招笔试第一题_第2张图片

解题代码:

粗暴而简单。大一的水平。 

package com.kyc.liantong;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        char[] input = in.next().toCharArray();
        int n = input.length;

        switch (n) {
            case 1:
                StringBuilder sb = new StringBuilder();
                for (int i = 1; i <= 3; i++) {
                    sb.append(input[0]).append(i).append(" ");
                }
                System.out.println(sb.substring(0, sb.length() - 1));
                break;
            case 2:
                StringBuilder sb2 = new StringBuilder();
                for (int i = 1; i <= 3; i++) {
                    for (int i1 = 1; i1 <= 3; i1++) {
                        sb2.append(input[0]).append(i).append(input[1]).append(i1).append(" ");
                    }
                }
                System.out.println(sb2.substring(0, sb2.length() - 1));
                break;

            case 3:
                StringBuilder sb3 = new StringBuilder();
                for (int i = 1; i <= 3; i++) {
                    for (int i1 = 1; i1 <= 3; i1++) {
                        for (int i2 = 1; i2 <= 3; i2++) {
                            sb3.append(input[0]).append(i)
                                    .append(input[1]).append(i1)
                                    .append(input[2]).append(i2).append(" ");
                        }
                    }
                }
                System.out.println(sb3.substring(0, sb3.length() - 1));
                break;

            case 4:
                StringBuilder sb4 = new StringBuilder();
                for (int i = 1; i <= 3; i++) {
                    for (int i1 = 1; i1 <= 3; i1++) {
                        for (int i2 = 1; i2 <= 3; i2++) {
                            for (int i3 = 1; i3 <= 3; i3++) {
                                sb4.append(input[0]).append(i)
                                        .append(input[1]).append(i1)
                                        .append(input[2]).append(i2)
                                        .append(input[3]).append(i3).append(" ");
                            }
                        }
                    }
                }
                System.out.println(sb4.substring(0, sb4.length() - 1));
                break;

            case 5:

                StringBuilder sb5 = new StringBuilder();
                for (int i = 1; i <= 3; i++) {
                    for (int i1 = 1; i1 <= 3; i1++) {
                        for (int i2 = 1; i2 <= 3; i2++) {
                            for (int i3 = 1; i3 <= 3; i3++) {
                                for (int i4 = 1; i4 <= 3; i4++) {
                                    sb5.append(input[0]).append(i)
                                            .append(input[1]).append(i1)
                                            .append(input[2]).append(i2)
                                            .append(input[3]).append(i3)
                                            .append(input[4]).append(i4).append(" ");
                                }
                            }

                        }
                    }

                }
                System.out.println(sb5.substring(0, sb5.length() - 1));
                break;
            default:

        }
    }
}

 

 

你可能感兴趣的:(联通,java,校招,笔试,校园招聘)