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


     1 #include "stdio.h"
     2 
     3 int main(int argc, char const *argv[])
     4 {
     5     int num;
     6     while(scanf("%d", &num) != EOF)
     7     {
     8         int bvalue, svalue, gvalue, i; //百位,十位,个位
     9         if (num >= 1000 || num <= 0)
    10         {
    11             printf("error
    ");
    12             exit(0);
    13         }
    14 
    15         bvalue = num / 100;
    16         svalue = (num - bvalue * 100) / 10;
    17         gvalue = num - bvalue * 100 - svalue * 10;
    18 
    19         for(i = 0 ; i < bvalue ; i++)
    20         {
    21             printf("%c", 'B');
    22         }
    23 
    24         for(i = 0 ; i < svalue; i++)
    25         {
    26             printf("%c", 'S');
    27         }
    28 
    29         for (i = 1; i <= gvalue; ++i)
    30         {
    31             printf("%d", i);
    32         }
    33         printf("
    ");
    34 
    35     }
    36     return 0;
    37 }
  • 相关阅读:
    STM32使用定时器实现输入捕获
    Leetcode#101 Symmetric Tree
    Leetcode#100 Same Tree
    Leetcode#26 Remove Duplicates from Sorted Array
    Leetcode#27 Remove Element
    Leetcode#83 Remove Duplicates from Sorted List
    Leetcode#70 Climbing Stairs
    Leetcode#66 Plus One
    Leetcode#36 Valid Sudoku
    Leetcode#67 Add Binary
  • 原文地址:https://www.cnblogs.com/hello-lijj/p/6472793.html
Copyright © 2011-2022 走看看