zoukankan      html  css  js  c++  java
  • PAT乙级题库“傻瓜”题解之输出PATest

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

    输入格式:

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

    输出格式:

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

    输入样例:

    redlesPayBestPATTopTeePHPereatitAPPT
    

    输出样例:

    PATestPATestPTetPTePePee

     1 #include<iostream>
     2 #include<string>
     3 using namespace std;
     4 int main()
     5 {
     6     string str;
     7     cin>>str;
     8     int x[150]={0};
     9     for(int i=0;i<str.length();i++)
    10     {
    11         if(str[i]=='P'||str[i]=='A'||str[i]=='T'||str[i]=='e'||str[i]=='s'||str[i]=='t')
    12         x[str[i]]++;
    13     }    
    14     while(1)
    15     {
    16         if(x[80]==0&&x[65]==0&&x[84]==0&&x[101]==0&&x[115]==0&&x[116]==0) break;
    17         if(x[80])
    18         {
    19             cout<<'P';
    20             x[80]--;
    21         }
    22         if(x[65])
    23         {
    24             cout<<'A';
    25             x[65]--;
    26         }
    27         if(x[84])
    28         {
    29             cout<<'T';
    30             x[84]--;
    31         }
    32         if(x[101])
    33         {
    34             cout<<'e';
    35             x[101]--;
    36         }
    37         if(x[115])
    38         {
    39             cout<<'s';
    40             x[115]--;
    41         }
    42         if(x[116])
    43         {
    44             cout<<'t';
    45             x[116]--;
    46         }
    47      } 
    48     return 0;
    49  } 
     
  • 相关阅读:
    2018年10月22日-Python day1
    Python list(列表)功能详解
    剑指offer(4):重建二叉树
    剑指offer(3):从尾到头打印单链表
    剑指offer(2):替换空格
    机器学习实战:第九章 树回归
    ubuntu 中查找文件的命令
    关于 c++ primer plus 中valarray类使用例程的一个记录
    vim 最基本操作
    如何在VS2015中使用strcpy函数
  • 原文地址:https://www.cnblogs.com/solititude/p/11830818.html
Copyright © 2011-2022 走看看