PAT (Basic Level) Practice (中文)1043 输出PATest (20 分)

时间:2022-07-26
本文章向大家介绍PAT (Basic Level) Practice (中文)1043 输出PATest (20 分),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1043 输出PATest (20 分)

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

输入格式:

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

输出格式:

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

输入样例:

redlesPayBestPATTopTeePHPereatitAPPT

输出样例:

PATestPATestPTetPTePePee

桶排字符,最后输出的时候一个个倒出来~,先整体输出PATest,不够PATest的话就按顺序输出就好~

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#include<unordered_set>
#define rg register ll
#define inf 2147483647
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define ll long long
#define maxn 300005
#define lb(x) (x&(-x))
const double eps = 1e-6;
using namespace std;
inline ll read()
{
	char ch = getchar(); ll s = 0, w = 1;
	while (ch < 48 || ch>57) { if (ch == '-')w = -1; ch = getchar(); }
	while (ch >= 48 && ch <= 57) { s = (s << 1) + (s << 3) + (ch ^ 48); ch = getchar(); }
	return s * w;
}
inline void write(ll x)
{
	if (x < 0)putchar('-'), x = -x;
	if (x > 9)write(x / 10);
	putchar(x % 10 + 48);
}
ll a[10];
string p="PATest";
int main()
{
    string s;
    cin>>s;
    for(rg i=0;s[i];i++)
    {
        if(s[i]=='P')a[1]++;
        if(s[i]=='A')a[2]++;
        if(s[i]=='T')a[3]++;
        if(s[i]=='e')a[4]++;
        if(s[i]=='s')a[5]++;
        if(s[i]=='t')a[6]++;
    }
    ll k=*min_element(a+1,a+1+6);
    for(rg i=1;i<=k;i++)cout<<p;
    for(rg i=1;i<=6;i++)a[i]-=k;;
    while(*max_element(a+1,a+1+6)>0)
    {
        for(rg i=1;i<=6;i++)
        {
            if(a[i]>0)
            {
                cout<<p[i-1];
                a[i]--;
            }
        }
    }
   	return 0;
}