1006. 换个格式输出整数 (15)
让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个“百”、3个“十”、以及个位的4。
输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000)。
输出格式:每个测试用例的输出占一行,用规定的格式输出n。
输入样例1:234输出样例1:
BBSSS1234输入样例2:
23输出样例2:
SS123
1 #include<iostream> 2 using namespace std; 3 int main(){ 4 string B[10]={"\0","B","BB","BBB","BBBB","BBBBB", 5 "BBBBBB","BBBBBBB","BBBBBBBB","BBBBBBBBB"}; 6 string S[10]={"\0","S","SS","SSS","SSSS","SSSSS", 7 "SSSSSS","SSSSSSS","SSSSSSSS","SSSSSSSSS"}; 8 string n[10]={"\0","1","12","123","1234","12345", 9 "123456","1234567","12345678","123456789"}; 10 int num; 11 cin>>num; 12 int b,s,n0; 13 string str; 14 n0=num%10; 15 num/=10; 16 s=num%10; 17 num/=10; 18 b=num%10; 19 str=B[b]+S[s]+n[n0]; 20 cout<<str; 21 return 0; 22 }