https://pintia.cn/problem-sets/994805260223102976/problems/994805318855278592
3.8改进版本
#include<iostream>
#include<string>
using namespace std;
int main(){
int n;
string str, res;
cin >> str;
for(int i=str.size()-1; i>=0; i--){
n = str[i]-'0';
if(i == str.size()-1){
for(int j=1; j<=n; j++){
res += to_string(j);
}
}else if(i == str.size()-2){
for(int j=1; j<=n; j++){
res = 'S' + res;
}
}else if(i == str.size()-3){
for(int j=1; j<=n; j++){
res = 'B' + res;
}
}
}
cout << res << endl;
return 0;
}
2.1版本
这题看似简单但是把我给气到了。
但其实是我没理解到题意。题意是,输入一个小于1000的数,百位上的数是几,就输出几个B,十位上的数是几,就输出几个S, 个位上的数是几,就输出1到几。
如:输入334,则需要输出BBBSSS1234。
#include<iostream>
#include<string>
using namespace std;
int main(){
int n, m, q, pos = 0;
string ch[3]={" ", "S", "B"};
string str="";
cin >> n;
q = n%10;
while(n != 0){
m = n % 10;
while(pos != 0 && m--){
str.insert(0, ch[pos]);
}
pos++;
n /= 10;
}
cout << str;
for(int i=1; i<=q; i++){
cout << i;
}
return 0;
}
最后通过了~