第一个方法:
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n, h, t, o;
    cin >> n;
    h = n / 100;  // 对于每位数的求解不能出错
    t = n / 10 % 10;
    o = n % 100 % 10;
    if (h != 0){ // 要使用连续的是那个if,而不是 else if 
        for (int i = 0; i < h; i++)
            cout << 'B';
    }
    if (t != 0){
        for (int j = 0; j < t; j++)            
            cout << 'S';
    }
    if (o != 0){
        for (int k = 1; k <= o; k++)
            cout << k;
    }
    cout << endl;
    return 0;
}

第二个方法:
#include <iostream>

using namespace std;

int main()
{
    int n, i = 0, a[10] = {0};
    cin >> n;
    while (n != 0)。// 利用已经给定的条件,巧妙设置
    {
        a[i++] = n % 10;
        n /= 10;
    }
    for (int j = i; j >= 0; j--)
    {
        for (int k = 0; k < a[j]; k++)
        {
            if (j == 2)
                cout << "B";
            if (j == 1)
                cout << "S";
            if (j == 0)
            {
                for (int l = 1; l <= a[j]; l++)
                {
                    cout << l;
                }
                break;
            }
        }
    }
    cout << endl;
    return 0;
}

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。