PAT: 1006 to change the format of the output integer (c language version)

Let B be represented by the letter "hundred", the letter S represents a positive integer "ten", denoted by 12 ... n is not zero digit n (<10), any change to the output format of a no more than three . 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:
Each test row for output, n output with a predetermined format.

Sample Input 1:
234

Output Sample 1:
BBSSS1234

Input Sample 2:
23

Output Sample 2:
SS123

#include <stdio.h>

int main()
{
    int i, d1, d2, d3, n;

    scanf("%d", &n);
    d1 = n / 100;
    d2 = n / 10 % 10;
    d3 = n % 10;
    for (i = 0; i < d1; i++)
        printf("B");
    for (i = 0; i < d2; i++)
        printf("S");
    for (i = 0; i < d3; i++)
        printf("%d", i + 1);

    return 0;
}
Published 24 original articles · won praise 0 · Views 149

Guess you like

Origin blog.csdn.net/qq_45624989/article/details/105105362