PAT-乙级-1043 输出PATest

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

输入格式:

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

输出格式:

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

输入样例:

redlesPayBestPATTopTeePHPereatitAPPT

输出样例:

PATestPATestPTetPTePePee



分析:
  统计输入的字符串中"PATest"各有多少个
  再按顺序输出即可


 1 //c++
 2 
 3 #include<iostream>
 4 using namespace std;
 5 
 6 int main(){
 7   char str[10010];
 8   char cst[7]="PATest";
 9   int cnt[6]={0};
10   cin>>str;
11   for(int i=0;str[i]!='\0';i++){
12     switch(str[i]){
13       case 'P':cnt[0]++;break;
14       case 'A':cnt[1]++;break;
15       case 'T':cnt[2]++;break;
16       case 'e':cnt[3]++;break;
17       case 's':cnt[4]++;break;
18       case 't':cnt[5]++;break;
19     }
20   }
21   int sum=0;
22   for(int i=0;i<6;i++)
23     sum+=cnt[i];
24   while(sum--){
25     for(int i=0;i<6;i++){
26       if(cnt[i]){
27         cout<<cst[i];
28         cnt[i]--;
29       }
30     }
31   }
32   return 0;
33 }

 

posted @ 2018-10-28 22:49  T丶jl  阅读(121)  评论(0编辑  收藏  举报