让我们用字母 B
来表示“百”、字母 S
表示“十”,用 12...n
来表示不为零的个位数字 n
(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234
应该被输出为 BBSSS1234
,因为它有 2 个“百”、3 个“十”、以及个位的 4。
输入格式:
每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。
输出格式:
每个测试用例的输出占一行,用规定的格式输出 n。
新学了一个函数,在某些程度上能够替代for循环
string s;
s.append(length,char);
to_string()函数 将整型转为字符串类型
C++
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int n;
cin >> n;
int hun = n / 100;
int ten = n % 100 / 10;
int ge = n % 10;
string s;
s.append(hun, 'B');
s.append(ten, 'S');
for (int i = 1; i <= ge; i++)
s += to_string(i);
cout << s << endl;
return 0;
}