227

234

BBSSS1234

23

SS123

# 代码

## C++解法

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
cin.sync_with_stdio(false);
cin.tie(0);

string s;
cin >> s;
int pos = s.size();

string ans = "";
for (char c : s) {
int cnt = c -= '0';
for (int i = 1; i <= cnt; ++i) {
if (pos == 3)
ans += "B";
if (pos == 2)
ans += "S";
if (pos == 1)
ans += i + '0';
}
--pos;
}
cout << ans << endl;

return 0;
}

## Python解法

n = int(input())
print(('B' * ((n // 100) % 10)) + ('S' * ((n // 10) % 10)) +
"".join([str(i) for i in range(1, (n % 10) + 1)]))

## Java解法

import java.util.*;

class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
String ans = "";
int pos = s.length();
for (int i = 0; i < s.length(); ++i) {
int cnt = s.charAt(i) - '0';
for (int j = 1; j <= cnt; ++j) {
if (pos == 3)
ans += "B";
if (pos == 2)
ans += "S";
if (pos == 1)
ans += j;
}
--pos;
}
System.out.println(ans);
in.close();
}
}

• 点击查看/关闭被识别为广告的评论