题目链接
《算法笔记》上面的思路很常规,但是一开始没想到这么写,用了一种更粗暴简单的思路,如下:
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(){
char str[10010], pat[]="PATest";
cin.getline(str,sizeof(str));
int len1=strlen(str);
int hash[300]={0};
for (int i=0; i<len1; i++){
hash[str[i]]++;
}
int flag=1;
while (flag){
flag=0;
for (int i=0; i<6; i++){
if (hash[pat[i]]){
printf("%c",pat[i]);
hash[pat[i]]--;
flag=1;
}
}
}
}
无脑然而有效。