Exam PAT B - change the output format integer

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 formats:

Each test comprises a test input, given a positive integer n (<1000).

Output formats:

Each output test case per line, with n predetermined output format.

Sample Input 1:

234

Output Sample 1:

BBSSS1234

Sample Input 2:

23

Output Sample 2:

SS123

#include <cstdio>

int main()
{
	int num;
	scanf("%d",&num);
	
	int digit;
	if(num<10) digit=1;
	else if(num<100) digit=2;
	else digit=3;

	int i;
	switch(digit)
	{
		case 3:
			for(i=0; i<num/100; i++)
				printf("B");
			num-=num/100*100;
		case 2:
			for(i=0; i<num/10; i++)
				printf("S");
			num-=num/10*10;
		case 1:
			for(i=0; i<num; i++)
				printf("%d",i+1);
	}
	return 0;
}
Published 35 original articles · won praise 2 · Views 904

Guess you like

Origin blog.csdn.net/qq_45735810/article/details/104077385