PAT——1043. 输出PATest

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

输入格式:

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

输出格式:

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

输入样例:

redlesPayBestPATTopTeePHPereatitAPPT

输出样例:

PATestPATestPTetPTePePee

 

 1 package com.hone.basical;
 2 
 3 import java.util.Scanner;
 4 import java.util.ArrayList;
 5 import java.util.List;
 6 /**
 7  * 原题目:https://www.patest.cn/contests/pat-b-practise/1043
 8  * @author Xia
 9  *思路:遍历所有的字符,然后用list存储起来 再一次又一次遍历Patest直到所有的都为零。
10  */
11 
12 public class basicalLevel1043printfPatTest {
13 
14     public static void main(String[] args) {
15 
16         Scanner in = new Scanner(System.in);
17         String string = in.nextLine();
18         in.close();
19 
20         List<Character> PList = new ArrayList<>();
21         List<Character> AList = new ArrayList<>();
22         List<Character> TList = new ArrayList<>();
23         List<Character> eList = new ArrayList<>();
24         List<Character> sList = new ArrayList<>();
25         List<Character> tList = new ArrayList<>();
26 
27         for (int i = 0; i < string.length(); i++) {
28             switch (string.charAt(i)) {
29             case 'P':
30                 PList.add(string.charAt(i));
31                 break;
32             case 'A':
33                 AList.add(string.charAt(i));
34                 break;
35             case 'T':
36                 TList.add(string.charAt(i));
37                 break;
38             case 'e':
39                 eList.add(string.charAt(i));
40                 break;
41             case 's':
42                 sList.add(string.charAt(i));
43                 break;
44             case 't':
45                 tList.add(string.charAt(i));
46                 break;
47 
48             }
49         }
50 
51         int maxSize = PList.size();
52         if (AList.size() > maxSize) {
53             maxSize = AList.size();
54         }
55         if (TList.size() > maxSize) {
56             maxSize = TList.size();
57         }
58         if (eList.size() > maxSize) {
59             maxSize = eList.size();
60         }
61         if (sList.size() > maxSize) {
62             maxSize = sList.size();
63         }
64         if (tList.size() > maxSize) {
65             maxSize = tList.size();
66         }
67         for (int i = 0; i < maxSize; i++) {
68 
69             if (i < PList.size()) {
70                 System.out.print(PList.get(i));
71             }
72             if (i < AList.size()) {
73                 System.out.print(AList.get(i));
74             }
75             if (i < TList.size()) {
76                 System.out.print(TList.get(i));
77             }
78             if (i < eList.size()) {
79                 System.out.print(eList.get(i));
80             }
81             if (i < sList.size()) {
82                 System.out.print(sList.get(i));
83             }
84             if (i < tList.size()) {
85                 System.out.print(tList.get(i));
86             }
87         }
88     }
89 }

 

posted @ 2017-12-06 11:03  SnailsCoffee  阅读(210)  评论(0编辑  收藏  举报