题目

redlesPayBestPATTopTeePHPereatitAPPT

PATestPATestPTetPTePePee

源代码

//C/C++实现
#include <iostream>
#include <string.h>

using namespace std;

int main(){
char c[10001];
gets(c);
int countP = 0, countA = 0, countT = 0, counte = 0, counts = 0, countt = 0;
for(int i = 0; i < strlen(c); ++i){
if(c[i] == 'P'){
++countP;
}
else if(c[i] == 'A'){
++countA;
}
else if(c[i] == 'T'){
++countT;
}
else if(c[i] == 'e'){
++counte;
}
else if(c[i] == 's'){
++counts;
}
else if(c[i] == 't'){
++countt;
}
}
while(countP != 0 || countA !=0 || countT !=0 || counte != 0 || counts !=0 || countt !=0){
if(countP != 0){
printf("P");
--countP;
}
if(countA != 0){
printf("A");
--countA;
}
if(countT != 0){
printf("T");
--countT;
}
if(counte != 0){
printf("e");
--counte;
}
if(counts != 0){
printf("s");
--counts;
}
if(countt != 0){
printf("t");
--countt;
}
}
printf("\n");
return 0;
}


//Java实现
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.next();
char[] c = s.toCharArray();
boolean flag = true;
int cP = 0,cA = 0,cT = 0,ce = 0,cs = 0,ct = 0;
if(s.length() >=1  && s.length() <=10000){
for(int i=0;i<s.length();i++){
if(c[i] >= 65 && c[i] <= 90 || c[i] >=97 && c[i] <=122){
if(c[i] == 'P'){
cP ++;
}
else if(c[i] == 'A'){
cA ++;
}
else if(c[i] =='T'){
cT ++;
}
else if(c[i] =='e'){
ce ++;
}
else if(c[i] =='s'){
cs ++;
}
else if(c[i] == 't'){
ct ++;
}
continue;
}
else{
flag = false;
break;
}
}
if(flag) {
while(cP != 0 || cA !=0 || cT !=0 || ce != 0 || cs !=0 || ct !=0){
if(cP != 0){
System.out.print('P');
cP --;
}
if(cA != 0){
System.out.print('A');
cA --;
}
if(cT != 0){
System.out.print('T');
cT --;
}
if(ce != 0){
System.out.print('e');
ce --;
}
if(cs != 0){
System.out.print('s');
cs --;
}
if(ct != 0){
System.out.print('t');
ct --;
}
}
System.out.println();
}
}
}
}