zoukankan      html  css  js  c++  java
  • PAT 乙级 1043 输出PATest(20) C++版

    1043. 输出PATest(20)

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    CHEN, Yue

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

    输入格式:

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

    输出格式:

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

    输入样例:
    redlesPayBestPATTopTeePHPereatitAPPT
    
    输出样例:
    PATestPATestPTetPTePePee

     1 // 1043.cpp : 定义控制台应用程序的入口点。
     2 //
     3 
     4 #include "stdafx.h"
     5 #include<iostream>
     6 #include<string>
     7 #include<stack>
     8 
     9 using namespace std;
    10 
    11 void judge(stack<char>& s, int& b);
    12 
    13 int main()
    14 {
    15     string str;
    16     int b = 1;
    17     stack<char> P,A,T,e,s,t;
    18 
    19     getline(cin,str);
    20 
    21     int size = str.size();
    22 
    23     for (int i = 0; i<size; ++i)
    24     {
    25         switch (str[i])
    26         {
    27         case 'P':P.push(str[i]); break;
    28         case 'A':A.push(str[i]); break;
    29         case 'T':T.push(str[i]); break;
    30         case 'e':e.push(str[i]); break;
    31         case 's':s.push(str[i]); break;
    32         case 't':t.push(str[i]); break;
    33         default:break;
    34         }
    35     }
    36 
    37     while (b)
    38     {
    39         b = 0;
    40 
    41         judge(P, b);
    42         judge(A, b);
    43         judge(T, b);
    44         judge(e, b);
    45         judge(s, b);
    46         judge(t, b);
    47     }
    48 
    49     cout << endl;
    50     
    51     return 0;
    52 }
    53 
    54 void judge(stack<char>& s,int& b)
    55 {
    56     if (!s.empty())
    57     {
    58         cout << s.top();
    59 
    60         s.pop();
    61         b = 1;
    62     }
    63 }
  • 相关阅读:
    windows下安装mysql教程
    python生成器实现杨辉三角
    python默认参数问题
    python中判断素数的函数
    extract()和extact_first()的区别
    硬连接和软连接的区别
    du与df的区别
    命题逻辑
    关于 better-scroll 设置了以后无法滚动或不生效的问题
    Maven *IDEA*
  • 原文地址:https://www.cnblogs.com/cdp1591652208/p/7256231.html
Copyright © 2011-2022 走看看