让我们用字母 B
来表示“百”、字母 S
表示“十”,用 12...n
来表示不为零的个位数字 n
(<10),换个格式来输出任一个不超过 3 位的正整数。例如 234
应该被输出为 BBSSS1234
,因为它有 2 个“百”、3 个“十”、以及个位的 4。
输入格式:
每个测试输入包含 1 个测试用例,给出正整数 n(<1000)。
输出格式:
每个测试用例的输出占一行,用规定的格式输出 n。
输入样例 1:
234
输出样例 1:
BBSSS1234
输入样例 2:
23
输出样例 2:
SS123
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
解题思路:
先运用除法得出百位,十位,个位上的数字,然后依据得出的数字输出相应个数的“B”、“S”,再用for循环按要求输出个位上的数。
解题代码:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[])
{
int n;
scanf("%d",&n);
int bai,shi1,shi2,g;
bai=n/100;
shi1=n%100;
shi2=shi1/10;
g=shi1%10;
while(bai--)
{
printf("B");
}
while(shi2--)
{
printf("S");
}
for(int i=1;i<=g;i++)
{
printf("%d",i);
}
return 0;
}