• 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;
    }
  • 相关阅读:
    一个群发站内信的设计
    javascript typeof 小结
    setInterval,setTimeout的用法
    C#中常见异常类
    输入框关闭自动完成功能
    【转】javascript判断一个元素是否数组
    jquery的动态统计输入字符数方法
    giedview绑定数据格式化字符串
    jQuery 1.4单独为某个动画动作设效果
    GridView行编辑中找DropDownList控件
  • 原文地址:https://www.cnblogs.com/2015-16/p/13540438.html
Copyright © 2020-2023  润新知