PAT - Class B 1043 Output PATest

1043. output PATest(20)

time limit
400 ms
memory limit
65536 kB
code length limit
8000 B
Judgment procedure
Standard
author
CHEN, Yue

Given a string consisting of only English letters of length 10000 or less. Please reorder the characters and output them in the order of "PATestPATest...." and ignore other characters. Of course, the number of six characters is not necessarily the same. If a certain character has been output, the remaining characters are still printed in the order of PATest until all characters are output.

Input format:

Input gives a non-empty string of only English letters of length 10000 or less in one line.

Output format:

Output the sorted string as required by the title in one line. The title guarantees that the output is not empty.

Input sample:
redlesPayBestPATTopTeePHPereatitAPPT
Sample output:
PATestPATestPTetPTePePee

#include<cstdio>
#include<cstring>
using namespace std;

int main(){
	char arr[10005], ans[6];
	gets(arr);
	memset(ans, 0, sizeof(ans));
	int n = strlen(arr);
	for(int i = 0; i < n; i++){
		if(arr[i] == 'P') ans[0]++;
		else if(arr[i] == 'A') ans[1]++;
		else if(arr[i] == 'T') ans[2]++;
		else if(arr[i] == 'e') ans[3]++;
		else if(arr[i] == 's') ans[4]++;
		else if(arr[i] == 't') ans[5]++;
	}
	int flag = 0;
	while(!flag){
		for(int i = 0 ; i < 6; i++){
			if(ans[i] != 0){
				if(i == 0) printf("P");
				else if(i == 1) printf("A");
				else if(i == 2) printf("T");
				else if(i == 3) printf("e");
				else if(i == 4) printf("s");
				else if(i == 5) printf("t");
				years[i]--;
			}	
		}
		for(int i = 0 ; i < 6; i++){
			if(ans[i] != 0) break;
			else if(i == 5)flag = 1;
		}
	}
	return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325754435&siteId=291194637