zoukankan      html  css  js  c++  java
  • 1006. 换个格式输出整数 (15)

    让我们用字母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()
    {
        int n;
        int i;
        int length;
        int num;
        int count;//用来计算十位、百位数字,以用来输出count个'B'或'S' 
        char str[1000]; 
        scanf("%s",str);
        length = strlen(str);//取出字符串的长度 
        num = atoi(str);//字符串str转到int整形
        
        if(length==1)
        {
            for(i=1;i<=num;i++)
            {
                printf("%d",i);//输出从1到num个连续的数
            }    
        }
        else if(length==2){
            count=num/10;//求出十位的那个数 
            for(i=1;i<=count;i++)
                printf("%c",'S');//输出count个'S' 
            for(i=1;i<=num%10;i++)
                printf("%d",i);//输出从1到num%10个连续的数 
        }
        else{
            count=num/100;//求出百位的那个数
            for(i=1;i<=count;i++)
                printf("%c",'B');//输出count个'B'
            count=(num/10)%10;//求出十位的那个数
            for(i=1;i<=count;i++)
                printf("%c",'S');//输出count个'S' 
            for(i=1;i<=num%10;i++)
                printf("%d",i); //输出从1到num%10个连续的数 
        }
        return 0;
    }
  • 相关阅读:
    UIScrollView 截图
    cocoapods import 第三方 自动补全
    UIWebView内存泄露问题解决方法
    iOS常用小控件集合
    UIViewController视图控制器视图的生命周期
    UIView
    UITextField
    UITabBar UITabBarController
    iOS图片相似度比较
    iOS获取已安装的app列表(私有库)+ 通过包名打开应用
  • 原文地址:https://www.cnblogs.com/dreamcoding/p/7287204.html
Copyright © 2011-2022 走看看