PAT B級1006:フォーマット変換出力整数(15)


タイトル:
「百」をアルファベットBで表し、「十」をアルファベットSで表し、「12…n」でビット数n(<10)を表し、フォーマットを変えて3ビット以下の正の整数を出力する.例えば234は、2個の「百」、3個の「十」、およびビットの4があるため、BBSSS 1234に出力されるべきである.
入力フォーマット:各テスト入力には1つのテスト例が含まれ、正の整数n(<1000)が与えられる.
出力フォーマット:各試験例の出力が1行を占め、nを所定のフォーマットで出力する.
サンプル1を入力:
234

出力サンプル1:
BBSSS1234

入力サンプル2:
23

出力サンプル2:
SS123

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

class Solution{
	public:
		string Convert(int n){
			//       、 、       
			int hundred = n / 100;
			int decade = (n / 10) % 10;
			int unit = n % 10;
			
			string str;//        ,        
			for (int i = 0; i < hundred; i++){
				str += 'B';
			}
			for (int i = 0; i < decade; i++){
				str += 'S';
			}
			for (int i = 0; i < unit; i++){
				str += (49+i);
			}
			
			return str;
		}
};
int main(){
	int n;
	cin >> n;
	
	Solution ans;
	cout << ans.Convert(n) << endl;
	
	return 0;
}