PAT (Basic Level) Practise (中文) 1006. 换个格式输出整数 (15)

来源:互联网 发布:p台词的软件 编辑:程序博客网 时间:2024/05/01 06:40

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

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

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

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

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

输入样例1:
234
输出样例1:
BBSSS1234
输入样例2:
23
输出样例2:
SS123
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Main{  public static void main(String[] args) throws IOException {    BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));    String str1=bf.readLine();    String str2="";    char arr[]=str1.toCharArray();    switch (arr.length) {    case 3:      int arr_n[]=new int[3];      arr_n[0]=Integer.parseInt(arr[0]+"");      for (int i = 0; i <arr_n[0]; i++) {        str2+="B";      }      arr_n[1]=Integer.parseInt(arr[1]+"");      for (int i = 0; i < arr_n[1]; i++) {        str2+="S";      }      arr_n[2]=Integer.parseInt(arr[2]+"");      for (int i = 1; i <=arr_n[2]; i++) {        str2+=i;      }      break;    case 2:      int[] arr_n2=new int[2];      arr_n2[0]=Integer.parseInt(arr[0]+"");      for (int i = 0; i < arr_n2[0]; i++) {        str2+="S";      }      arr_n2[1]=Integer.parseInt(arr[1]+"");      for (int i = 1; i <=arr_n2[1]; i++) {        str2+=i;      }      break;    case 1:      int arr_n3=Integer.parseInt(arr[0]+"");      for (int i = 1; i <=arr_n3; i++) {        str2+=i;      }        }    System.out.println(str2);      }}

阅读全文
0 0
原创粉丝点击