1006. Output an integer (15) in another format (zjupat)

Source: Internet
Author: User

Link: http://pat.zju.edu.cn/contests/pat-b-practise/1006


Let's use the letter B to represent "Hundred", the letter S to represent "Ten", and "12... N (<10) is a single digit. In another format, a positive integer of no more than three digits is output. For example, 234 should be output as bbsss1234 because it has two "hundreds", three "Ten", and four digits.

Input Format:Each test input contains one test case and a positive integer N (<1000 ).

Output Format:The output of each test case occupies one line and outputs N in the specified format.

Input Example 1:
234
Output Example 1:
BBSSS1234
Input Example 2:
23
Output Example 2:
SS123


The Code is as follows:

#include <cstdio>#include <cstring>char s[4];void solve(char s[]){    int len = strlen(s);    for(int i = 0; i < len; i++)    {        if(len == 3 && i == 0)        {            for(int j = 0; j < s[i]-'0'; j++)            {                printf("B");            }        }        else if(len == 3 && i == 1)        {            for(int j = 0; j < s[i]-'0'; j++)            {                printf("S");            }        }        else if(len == 2 && i == 0)        {            for(int j = 0; j < s[i]-'0'; j++)            {                printf("S");            }        }        else        {            for(int j = 1; j <= s[i]-'0'; j++)            {                printf("%d",j);            }        }    }}int main(){    while(~scanf("%s",s))    {        solve(s);        printf("\n");    }    return 0;}


1006. Output an integer (15) in another format (zjupat)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.