長さが104を超えない英語の文字列があるとします。文字の順序を再調整PATestPATest....
し、この順序で出力し、 他の文字は無視してください。もちろん、6文字の数は必ずしも同じではありません。特定の文字が出力された場合、残りの文字は、すべての文字が出力されるまで、PATestの順序で印刷されます。
入力フォーマット:
1行に104を超えない空でない英字の文字列を入力します。
出力フォーマット:
タイトルの要件に従って、ソートされた文字列を1行で出力します。タイトルは、出力が空でないことを保証します。
入力サンプル:
redlesPayBestPATTopTeePHPereatitAPPT
サンプル出力:
PATestPATestPTetPTePePee
コード:
#include<bits/stdc++.h>
using namespace std;
int main(){
string str;
cin>>str;
map<char,int> m;
for(int i=0;i<str.size();i++)
m[str[i]]++;
int P=m['P'],A=m['A'],T=m['T'],e=m['e'],s=m['s'],t=m['t'];
int sum=P+A+T+e+s+t,cnt=0;
while(cnt!=sum){
if(P){
cout<<"P";
cnt++;
P--;
}
if(A){
cout<<"A";
cnt++;
A--;
}
if(T){
cout<<"T";
T--;
cnt++;
}
if(e){
cout<<"e";
cnt++;
e--;
}
if(s){
cout<<"s";
cnt++;
s--;
}
if(t){
cout<<"t";
cnt++;
t--;
}
}
return 0;
}
他の人が書いたより単純なwhileループ条件を見て、それから学びたいと思います:while(P | A | T | e | s | t ){......}