1. 程式人生 > >1006. 換個格式輸出整數 (15)

1006. 換個格式輸出整數 (15)

... scan clas print 整數 stdlib.h gpo 讓我 一個

讓我們用字母B來表示“百”、字母S表示“十”,用“12...n”來表示個位數字n(<10),換個格式來輸出任一個不超過3位的正整數。例如234應該被輸出為BBSSS1234,因為它有2個“百”、3個“十”、以及個位的4。

輸入格式:每個測試輸入包含1個測試用例,給出正整數n(<1000)。

輸出格式:每個測試用例的輸出占一行,用規定的格式輸出n。

輸入樣例1:

234

輸出樣例1:

BBSSS1234

輸入樣例2:

23

輸出樣例2:

SS123
 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 
 4 int main()
5 { 6 int n; 7 int ge,shi,bai; 8 int i; 9 while(scanf("%d",&n)!=EOF) 10 { 11 bai = n/100; //分解百位 12 ge = n%10; //分解個位 13 n /= 10; 14 shi = n%10; //分解十位 15 if( bai ) 16 { 17 for( i=0; i<bai; i++) 18 printf("
B"); 19 } 20 if( shi ) 21 { 22 for( i=0; i<shi; i++) 23 printf("S"); 24 } 25 if( ge ) 26 { 27 for( i=1; i<=ge; i++) 28 printf("%d",i); 29 } 30 printf("\n"); 31 } 32 return
0; 33 }

1006. 換個格式輸出整數 (15)