zoukankan      html  css  js  c++  java
  • L1-023 输出GPLT

    L1-023 输出GPLT (20分)
     

    给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按GPLTGPLT....这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。

    输入格式:

    输入在一行中给出一个长度不超过10000的、仅由英文字母构成的非空字符串。

    输出格式:

    在一行中按题目要求输出排序后的字符串。题目保证输出非空。

    输入样例:

    pcTclnGloRgLrtLhgljkLhGFauPewSKgt
    
     

    输出样例:

    GPLTGPLTGLTGLGLL

    我也不知道这么写有没有问题,但是确实简单的解决了问题。

    那就直接统计个数,然后按照顺序一个一个的排队输出,没有了的当然也就停止不在输出了。

    //#include<bits/stdc++.h> 
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <iomanip>        // 格式化输入输出 
    #include <cmath>
    #include <cstdlib> 
    #include <vector>
    
    using namespace std;
    
    void Function_023(int G,int P,int T,int L) {
        char a[4] = {'G','P','T','L'};
        while( G + P + T + L > 0 ) {
            if(G != 0) {
                cout<<a[0];
                G--;
            }
            if(P != 0) {
                cout<<a[1];
                P--;
            }
            if(L != 0) {
                cout<<a[3];
                L--;
            }
            if(T != 0) {
                cout<<a[2];
                T--;
            }
        }
    }
    
    int main()
    {
        string str;
        cin>>str;
        int G,P,T,L,i = 0;
        G = P = T = L = 0;
        while(i < str.length()) {
            if(str[i] == 'g' || str[i] == 'G')
                G++;
            if(str[i] == 'p' || str[i] == 'P')
                P++;
            if(str[i] == 't' || str[i] == 'T')
                T++;
            if(str[i] == 'l' || str[i] == 'L')
                L++;
            i++;
        }
        Function_023(G,P,T,L);
        return 0;
    }
  • 相关阅读:
    使用熔断器防止服务雪崩
    创建服务消费者(Feign)
    1.python进行if条件相等时候的条件
    理解编程语言是什么
    硬件架构与操作系统的历史
    centos7 下安装rpm的mysql 5.7
    BIND的进阶二:视图,日志,转发,子域的授权
    Linux启动盘-ultraiso
    ubuntu 跟xshell的问题
    Python接口自动化-requests模块之get请求
  • 原文地址:https://www.cnblogs.com/2015-16/p/13540438.html
Copyright © 2011-2022 走看看