[PAT B1006] to change the format of the output integer

Let B be represented by the letter "hundred", the letter S denotes "ten", with "12 ... n" to indicate a digit n (<10), any change in format to output a positive integer of not more than 3. 234 should be output as e.g. BBSSS1234, because it has two "hundred", 3 "ten", and 4 bits.
Input format: Each test input comprises a test gives a positive integer n (<1000).
Output format: one row for each output test, with n predetermined output format.
Sample Input 1:
234
Output Sample 1:
BBSSS1234
Input Sample 2:
23 is
output Sample 2:
SS123

#include <stdio.h>

int main() {
    int bai, shi, ge, num;

    scanf("%d", &num);
    bai = num / 100;
    shi = num / 10 % 10;
    ge = num % 10;

    for (int i = bai; i > 0; i--) {
        printf("B");
    }
    for (int i = shi; i > 0; i--) {
        printf("S");
    }
    for (int i = 1; i <= ge; i++) {
        printf("%d", i);
    }
    return 0;
}

Test Results:
Here Insert Picture Description

Published 33 original articles · won praise 1 · views 4140

Guess you like

Origin blog.csdn.net/qq_39827677/article/details/103934317