PAT B exam "Fool problem solution" of the output PATest

Given a length of not more than . 1 0 . 4 , the string composed only of letters. Please character re-adjust the order, according to this order output, and ignore other characters. Of course, the number of six kinds of characters is not necessarily as much, if some kind of character output has finished, the remaining characters based upon the order of PATest print until all characters are output.PATestPATest....

Input formats:

A given input row length does not exceed . 1 0 . 4 , the non-empty string composed only of letters.

Output formats:

Title character string in a row by ordering the required output. Topic ensure that the output is not empty.

Sample input:

redlesPayBestPATTopTeePHPereatitAPPT

Sample output:

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  } 

 

 

Guess you like

Origin www.cnblogs.com/solititude/p/11830818.html