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
    

    代码

    // 1006 换个格式输出整数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
    //
    
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int num;
        cin >> num;
        int a = num / 100;
        num %= 100;
        int b = num / 10;
        num %= 10;
        int c = num;
        if (a != 0) {
            for (int i = 0; i < a; i++) {
                cout << "B";
            }
        }
        if (b != 0) {
            for (int i = 0; i < b; i++) {
                cout << "S";
            }
        }
        if (c != 0) {
            for (int i = 1; i <= c; i++) {
                cout << i;
            }
        }
        
    
        return 0;
    }
    
    
  • 相关阅读:
    POJ 1315 Don't Get Rooked
    POJ 2051 Argus
    POJ 1942 Paths on a Grid
    POJ 2151 Check the difficulty of problems
    POJ 3349 Snowflake Snow Snowflakes
    POJ 1753 Flip Game
    POJ 2392 Space Elevator
    POJ 2385 Apple Catching
    POJ 2356 Find a multiple
    POJ 2355 Railway tickets
  • 原文地址:https://www.cnblogs.com/ericling/p/12331856.html
Copyright © 2011-2022 走看看