PAT B1043 输出PATest

PAT B1043 输出PATest

题目描述:

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

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

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

  输入样例:
  redlesPayBestPATTopTeePHPereatitAPPT

  输出样例:
  PATestPATestPTetPTePePee

参考代码:

 1 /****************************************************
 2 PAT B1043 输出PATest
 3 ****************************************************/
 4 #include <iostream>
 5 #include <string>
 6 #include <vector>
 7 
 8 using namespace std;
 9 
10 int main() {
11     string charList;
12     vector<int> Hash(125, 0);
13 
14     cin >> charList;
15 
16     for (int i = 0; i < charList.size(); ++i) {
17         Hash[charList[i]]++;
18     }
19 
20     while (!(Hash['P'] == 0 && Hash['A'] == 0 && Hash['T'] == 0 &&
21              Hash['e'] == 0 && Hash['s'] == 0 && Hash['t'] == 0)) {
22         if (Hash['P'] != 0) {
23             cout << 'P';
24             Hash['P']--;
25         }
26         if (Hash['A'] != 0) {
27             cout << 'A';
28             Hash['A']--;
29         }
30         if (Hash['T'] != 0) {
31             cout << 'T';
32             Hash['T']--;
33         }
34         if (Hash['e'] != 0) {
35             cout << 'e';
36             Hash['e']--;
37         }
38         if (Hash['s'] != 0) {
39             cout << 's';
40             Hash['s']--;
41         }
42         if (Hash['t'] != 0) {
43             cout << 't';
44             Hash['t']--;
45         }
46     }
47 
48     return 0;
49 }

注意事项:

  无。

posted @ 2019-10-12 14:57  多半是条废龙  阅读(90)  评论(0编辑  收藏  举报