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

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

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

输入格式:每个测试输入包含1个测试用例,给出正整数n(&lt1000)。

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

输入样例1:

234

输出样例1:

BBSSS1234

输入样例2:

23

输出样例2:

SS123
#include <iostream>
#include <algorithm>

using namespace std;

char num[100] ; 
int result[10] ; 
int total ; 

int main(){    
    int n ; 

    cin >> n ;
    total = 0 ;
    while(n){
        result[++total] = n % 10 ;
        n /= 10 ;
    }

    for(int i=total ; i>=1 ;i-- ){
        if(i==3){
            for(int j=1 ; j<= result[i] ; j++){
                cout << "B" ; 
            }
        }else if(i == 2){
            for(int j=1 ; j<= result[i] ; j++){
                cout << "S" ;
            }
        }else if(i == 1){
            for(int j=1 ; j<= result[i] ; j++){
                cout << j ; 
            }            
        }
    }
    cout << endl ; 
}
原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9107534.html