1006. Change format to output integer(15)
time limit
400 ms
memory limit
65536 kB
code length limit
8000 B
Judgment procedure
Standard
author
CHEN, Yue
Let's use the letter B for "hundred", the letter S for "ten", and "12...n" for the one digit n (<10), and change the format to output any positive integer with no more than 3 digits . For example 234 should be output as BBSSS1234 because it has 2 "hundreds", 3 "tens", and a 4 for the ones.
Input format: Each test input contains 1 test case, giving a positive integer n (<1000).
Output format: The output of each test case occupies one line, and outputs n in the specified format.
Input sample 1:234
Sample output 1:
BBSSS1234
Input sample 2:
23
Sample output 2:
SS123
----------------------------------------------------------------------------------------------------------
import java.util.Scanner; public class PAT_B_1006//In the PAT submission, the class name needs to be changed to Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt();//Receive the input number if((num/100) > 0)//If num is greater than or equal to 100 { for(int i = 0; i < num/100; i++)//Then num/100 represents the number in the hundreds place System.out.print("B"); num = num % 100;//Remove the hundreds of num to make num<100 } if((num/10) > 0)//If num is greater than or equal to 10 { for(int i = 0; i < num/10; i++)//Then num/10 represents the number in the tens place System.out.print("S"); num = num%10;//Remove the ten digits of num, so that num<10 } for(int i = 0; i < num; i++)//个位 System.out.print(i+1); } }