zoukankan      html  css  js  c++  java
  • PAT B1006 换个格式输出整数 (15 分)

    让我们用字母 B 来表示“百”、字母 S 表示“十”,用 12...n 来表示不为零的个位数字 n<),换个格式来输出任一个不超过 3 位的正整数。例如 234 应该被输出为 BBSSS1234,因为它有 2 个“百”、3 个“十”、以及个位的 4。

    输入格式:

    每个测试输入包含 1 个测试用例,给出正整数 n(<)。

    输出格式:

    每个测试用例的输出占一行,用规定的格式输出 n。

    输入样例 1:

    234
    

    输出样例 1:

    BBSSS1234
    

    输入样例 2:

    23
    

    输出样例 2:

    SS123
    #include <stdio.h>
    #include <algorithm>
    #include <string>
    #include <map>
    #include <iostream>
    #include <stack>
    using namespace std;
    const int maxn = 100;
    int index[3] = { 0 };
    int main(){
        int n;
        cin >> n;
        int pos = 2;
        while (n != 0){
            index[pos--] = n % 10;
            n /= 10;
        }
        for (int i = 0; i < index[0]; i++){
            cout << 'B';
        }
        for (int i = 0; i < index[1]; i++){
            cout << 'S';
        }
        for (int i = 0; i < index[2]; i++){
            cout << i+1;
        }
        system("pause");
    }

    注意点:输入整数不一定是三位数,所以不能用getchar直接来做。用数组倒着存也就是先进后出(filo),也可以用stack,但就需要判断大小了

    ---------------- 坚持每天学习一点点
  • 相关阅读:
    Tree Grafting
    敌兵布阵
    畅通工程(并查集)
    The Suspects(并查集)
    Ubiquitous Religions(friends变形)
    Friends(采用树结构的非线性表编程)
    小球下落(二叉树)
    铁轨
    卡片游戏
    征服C指针
  • 原文地址:https://www.cnblogs.com/tccbj/p/10359170.html
Copyright © 2011-2022 走看看