PAT Class B 1006 Change the format to output an integer (15 points)

PAT Level B exercise summary

PAT Class B 1006 Change the format to output an integer (15 points) I hope my ideas can help you.


1006 Change the format to output an integer (15 points)

Let us use the letter B to represent "hundred", the letter S to represent "ten", and use 12...n to represent the non-zero ones digit n (<10), and change the format to output any positive integer not exceeding 3 digits . For example, 234 should be output as BBSSS1234 because it has 2 "hundreds", 3 "tens", and 4 in the ones place.

输入格式:每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。
输出格式:每个测试用例的输出占一行,用规定的格式输出 n。
输入样例1:
234
输出样例1:
BBSSS1234
输入样例2:
23
输出样例2:
SS123

Two, the code

#include<stdio.h>
#define MAXS 101
int main(){
    
    
	int n,bai,shi,ge,i;
	scanf("%d",&n);
	ge=n%10;
	n/=10;
	shi=n%10;
	n/=10;
	bai=n%10;
	//printf("%d %d %d",bai,shi,ge);
	for(i=0;i<bai;i++){
    
    
		printf("B");
	}
	for(i=0;i<shi;i++){
    
    
		printf("S");
	}
	for(i=1;i<=ge;i++){
    
    
		printf("%d",i);
	}
	return 0;
}

Insert picture description here

to sum up

It's relatively simple, just take the remainder of each bit and output it several times.

Guess you like

Origin blog.csdn.net/jiaoooooo/article/details/114145149