code6

让我们用字母 B 来表示“百”、字母 S 表示“十”,用 12…n 来表示不为零的个位数字 n(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234 应该被输出为 BBSSS1234,因为它有 2 个“百”、3 个“十”、以及个位的 4。

import java.util.Scanner;
public class code15 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner in = new Scanner(System.in);
	String str = "";
	str = in.next();
	String[] str2 = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
	int x = Integer.parseInt(str);
	if (x > 1000) {
		System.out.println("no");
	}
	int[] arr = new int[str.length()];
	for (int i = 0; i < arr.length; i++) {
		arr[i] = Integer.parseInt(str.substring(i, i + 1));
	}
	if (str.length() == 1) {
		for (int i = 0; i < arr[0]; i++) {
			System.out.print(i + 1);
		}
	}
	if (str.length() == 2) {
		for (int i = 0; i < arr[0]; i++) {
			System.out.print("S");
		}
		for (int i = 0; i < arr[1]; i++) {
			System.out.print(i + 1);
		}
	}
	if (str.length() == 3) {
		for (int i = 0; i < arr[0]; i++) {
			System.out.print("B");
		}
		for (int i = 0; i < arr[1]; i++) {
			System.out.print("S");
		}
		for (int i = 0; i < arr[2]; i++) {
			System.out.print(i + 1);
		}
	}
}

}

直接爆破。。。。。。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41409907/article/details/88957108
今日推荐