讓我們用字母 B
來表示“百”、字母 S
表示“十”,用 12...n
來表示不爲零的個位數字 n
(<10),換個格式來輸出任一個不超過 3 位的正整數。例如 234
應該被輸出爲 BBSSS1234
,因爲它有 2 個“百”、3 個“十”、以及個位的 4。
輸入格式:
每個測試輸入包含 1 個測試用例,給出正整數 n(<1000)。
輸出格式:
每個測試用例的輸出佔一行,用規定的格式輸出 n。
輸入樣例 1:
234
輸出樣例 1:
BBSSS1234
輸入樣例 2:
23
輸出樣例 2:
SS123
C++示例代碼:
#include<iostream>
#include<string>
using namespace std;
int main() {
int n;cin>>n;
int b = n/100,s = (n%100)/10,g = (n%100)%10;
string res;
res.clear();
if(b) {
for(int i=0;i<b;i++)
res.append("B");
for(int i=0;i<s;i++)
res.append("S");
for(int i=0;i<g;i++)
string str = to_string(i+1);
res.append(str);
}
else {
if(s) {
for(int i=0;i<s;i++)
res.append("S");
for(int i=0;i<g;i++)
string str = to_string(i+1);
res.append(str);
}
else {
for(int i=0;i<g;i++)
string str = to_string(i+1);
res.append(str);
}
}
cout<<res<<endl;
return 0;
}