美文网首页
1006. 换个格式输出整数

1006. 换个格式输出整数

作者: Joving | 来源:发表于2018-01-11 17:31 被阅读39次

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

输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000)。

输出格式:每个测试用例的输出占一行,用规定的格式输出n。

输入样例1:

234

输出样例1:

BBSSS1234

输入样例2:

23

输出样例2:

SS123

idea:

  • 题目比较简单,对输入的数字进行取位并放for循环里得到对应的字符。这里用到StringBuffer来实现

代码:

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {

        Scanner shuru=new Scanner(System.in);
        int number=shuru.nextInt();
        StringBuilder result=new StringBuilder();
        if(number>99){
            int han=number/100;
            number=number%100;
            for (int i = 0; i < han; i++) {
                result.append("B");
            }
        }
        if(number>9){
            int ten=number/10;
            number=number%10;
            for (int i = 0; i < ten; i++) {
                result.append("S");
            }
        }
        if(number!=0){
            for (int i = 0; i < number; i++) {
                result.append(i+1);
            }
        }
        System.out.println(result);
    }
}

相关文章

  • 1006. 换个格式输出整数

    原题链接换个格式输出整数: 让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<1...

  • 1006. 换个格式输出整数

    让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不...

  • 1006.换个格式输出整数

    题目: 让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出...

  • 1006. 换个格式输出整数 (15)

    让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不...

  • 1006. 换个格式输出整数 (15)

    让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不...

  • 6~10题

    1006. 换个格式输出整数 (15) 很简单的一个题, 根据输入的不同的有2种写法都是可以的。输入的数字记为字符...

  • PAT 1006. 换个格式输出整数 (15)

    让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不...

  • PTA BASIC 1006.换个格式输出整数

    原题目链接 题解 没啥好说的

  • PAT-B 1006. 换个格式输出整数 (15)

    传送门 https://www.patest.cn/contests/pat-b-practise/1006 题目...

  • 1006换个格式输出整数

    问题描述 :让我们用字母 B 来表示“百”、字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n(<...

网友评论

      本文标题:1006. 换个格式输出整数

      本文链接:https://www.haomeiwen.com/subject/mjltoxtx.html