#include <iostream>
using namespace std;
int main() {
//定义字符串数组
string str[12] = { "1", "12", "123", "1234", "12345", "123456", "1234567", "12345678", "123456789","B", "S"};
int array[3];
string s;
while(s.size() > 3 || s.empty()){
cin >> s;
}
for (int i = 0; i < s.size(); ++i) {
array[i] = s[i] - '0';
}
if (s.size() == 3){
for (int i = 0; i < array[0]; ++i) {
cout << str[9];
}
for (int i = 0; i < array[1]; ++i) {
cout << str[10];
}
int index = array[2] - 1;
cout << str[index];
cout << endl;
}else if(s.size() == 2){
for (int i = 0; i < array[0]; ++i) {
cout << str[10];
}
int index = array[1] - 1;
cout << str[index];
cout << endl;
}else if(s.size() == 1){
int index = array[0] - 1;
cout << str[index];
cout << endl;
}
system("pause");
return 0;
}
让我们用字母 B
来表示“百”、字母 S
表示“十”,用 12...n
来表示不为零的个位数字 n
(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234
应该被输出为 BBSSS1234
,因为它有 2 个“百”、3 个“十”、以及个位的 4。
输入格式:
每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。
输出格式:
每个测试用例的输出占一行,用规定的格式输出 n。
输入样例 1:
234
输出样例 1:
BBSSS1234
输入样例 2:
23
输出样例 2:
SS123
若有问题欢迎指正,若有更好解法,还望在评论区给我留言