zoukankan      html  css  js  c++  java
  • PTA(BasicLevel)-1006换个格式输出整数

     
    一  换格式输出整数

            用字母 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>
    
    void outPutNum( int num );
    void printChar( int n, char c );
    
    int main(int argc, char *argv[])
    {
        int num;
        scanf("%d", &num);
        outPutNum( num );
        
        return 0;
    }
    
    void outPutNum( int num )
    {
        int i, hundred, ten, single;
    
        hundred = num / 100;
        ten =  (num % 100) / 10;
        single = num % 10; 
        printChar( hundred, 'B' );
        printChar( ten, 'S' );
        printChar( single, 'G' );    
    }
    
    void printChar( int n, char c )
    {  
        int i;
        if ( c == 'G' ) {
            /* 个位输出数字 */
            for ( i = 1; i <= n; i++ ) {
                printf("%d", i);
            }
        } else {
            for ( i = 1; i <= n; i++ ) {
                printf("%c", c);
            }    
        } 
    }
  • 相关阅读:
    全表扫描
    服务器信息表
    事务的丢失更新
    oracle core 概述
    oracle命中率模型计算
    性能量化之cpu
    一个sql导致temp表空间爆掉
    oracle稳定执行计划1
    oracle热点表online rename
    oracle构建一致性读
  • 原文地址:https://www.cnblogs.com/justLittleStar/p/10544567.html
Copyright © 2011-2022 走看看