zoukankan      html  css  js  c++  java
  • 07-1. 换个格式输出整数 (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 void print(int n);             //输出函数声明 
     4 
     5 int main()
     6 {
     7     int n;                     
     8     scanf("%d", &n);           //输入数字n 
     9     print(n);
    10             
    11     return 0;
    12 }
    13 
    14 void print(int n)              //输出函数 
    15 {
    16     int a, b ,c;               //a为百位数字,b为十位数字,c为个位数字 
    17     a = n / 100;
    18     b = n % 100 /10;
    19     c = n % 10;
    20     int i;
    21     for(i = 0;i < a;i++) {       
    22         printf("B");
    23     }
    24     for(i = 0;i < b;i++) {
    25         printf("S");
    26     }
    27     for(i = 1;i <= c;i++) {
    28         printf("%d", i);
    29     }
    30 }
  • 相关阅读:
    svn Mac
    webpack实用配置
    vuex状态管理-数据改变不刷新
    element-vue-koa2-mysql实现文件上传
    Promise的理解
    mysql Mac篇
    python 24 days
    python 7 days
    python 27 days
    python 26 days
  • 原文地址:https://www.cnblogs.com/aexin/p/3877657.html
Copyright © 2011-2022 走看看