1006. 换个格式输出整数 (15)

来源:互联网 发布:惠州乐知英语 编辑:程序博客网 时间:2024/05/16 15:17

让我们用字母B来表示“百”、字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个“百”、3个“十”、以及个位的4。

输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000)。

输出格式:每个测试用例的输出占一行,用规定的格式输出n。

输入样例1:
234
输出样例1:
BBSSS1234
输入样例2:
23
输出样例2:
SS123



#include<stdio.h>#include<string.h>int main(){    char s[4];    char str[50];    int len,p=0,i,j,temp;    scanf("%s",s);    len=strlen(s);    if(len==3){        temp=s[0]-'0';        for(i=0;i<temp;i++)            str[p++]='B';        len=2;        strcpy(s,s+1);    }    if(len==2){        temp=s[0]-'0';        for(i=0;i<temp;i++)            str[p++]='S';        len=1;        strcpy(s,s+1);    }    if(len==1){        temp=s[0]-'0';        for(i=0;i<temp;i++)            str[p++]='1'+i;    }    str[p]='\0';    printf("%s\n",str);}


原创粉丝点击