0
点赞
收藏
分享

微信扫一扫

PAT -1006 换个格式输出整数


                                                         1006 换个格式输出整数 (15 分)

让我们用字母 ​​B​​​ 来表示“百”、字母 ​​S​​​ 表示“十”,用 ​​12...n​​​ 来表示不为零的个位数字 ​​n​​​(<10),换个格式来输出任一个不超过 3 位的正整数。例如 ​​234​​​ 应该被输出为 ​​BBSSS1234​​,因为它有 2 个“百”、3 个“十”、以及个位的 4。

输入格式:

每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。

输出格式:

每个测试用例的输出占一行,用规定的格式输出 n。

输入样例 1:

234

输出样例 1:

BBSSS1234

输入样例 2:

23

输出样例 2:

SS123

 

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
#pragma GCC optimize(2)
#include <cmath>
#define pi 3.141592654
#include <stack>
using namespace std ;
const int MAX = 1005 ;
typedef long long LL ;
stack<char> st ;
void solve(int x ){
int t = x ;
int cnt = 0 ;
while(t){
cnt++ ;
if(cnt== 1 ){
int k = t%10 ;
while(k--){
// cout<<k-'0'<<" " ;
st.push(char(k+'0'+1 ));
}
}
if(cnt == 2){
int k = t%10 ;
while(k--){
st.push('S') ;
}
}
if(cnt == 3){
int k = t%10 ;
while(k--){
st.push('B') ;
}
}
t/=10 ;
}
}
int main()
{
int n ;
cin >>n ;
solve(n) ;
while(!st.empty()){
char ch = st.top() ;
cout<<ch ;
st.pop() ;
}

return 0;
}

 

举报

相关推荐

0 条评论