程序员测试题:PAT乙级 1006 换个格式输出整数(C语言版本)
思路:
题目简单,用简单的球磨\和秋雨%运算就可以。
#include<stdio.h>
int main()
{
int num;
scanf("%d",&num);
int ones,tens,hundreds;
if(num/10)
{
if(num/100)
{
hundreds = num/100;
for(;hundreds;hundreds--)
{
printf("B");
}
}
tens = (num/10)%10;//得出十位的数量
for(;tens;tens--)
{
printf("S");
}
}
ones = num%10;
int i;
for(i=1;i<=ones;i++)
{
printf("%d",i);
}
return 0;
}