PAT 1043. 输出PATest(20)

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

输入格式:

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

输出格式:

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

输入样例:

redlesPayBestPATTopTeePHPereatitAPPT

输出样例:

PATestPATestPTetPTePePee
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<stdlib.h>
 4 #include<ctype.h>
 5 #include<math.h>
 6 
 7 int main(){
 8     char a[10010];
 9     gets(a);
10     int lena = strlen(a);
11     int P,A,T,e,s,t;
12     P=0,A=0,T=0,e=0,s=0,t=0;
13     for(int i=0;i<lena;i++){
14         if(a[i]=='P')
15             P++;
16         if(a[i]=='A')
17             A++;
18         if(a[i]=='T')
19             T++;
20         if(a[i]=='e')
21             e++;
22         if(a[i]=='s')
23             s++;
24         if(a[i]=='t')
25             t++;
26     }
27     while(P||A||T||e||s||t){
28         if(P){
29             printf("P");
30             P--;
31         }
32         if(A){
33             printf("A");
34             A--;
35         }
36         if(T){
37             printf("T");
38             T--;
39         }
40         if(e){
41             printf("e");
42             e--;
43         }
44         if(s){
45             printf("s");
46             s--;
47         }
48         if(t){
49             printf("t");
50             t--;
51         }
52             
53     }
54 } 

 

posted @ 2016-12-30 19:37  来一点音乐  阅读(173)  评论(0编辑  收藏  举报