分析
代码
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
const int N = 10;
int g[N];
int main() {
string s;
cin >>s;
memset(g, 0, sizeof g);
for(auto c: s) {
if(c =='S') g[0]++;
else if(c =='t') g[1]++;
else if(c == 'r') g[2]++;
else if(c == 'i') g[3]++;
else if(c == 'n') g[4]++;
else if(c == 'g') g[5]++;
}
while(g[0] || g[1] || g[2] || g[3] || g[4] || g[5]) {
if(g[0]) cout<<"S", g[0]--;
if(g[1]) cout<<"t", g[1]--;
if(g[2]) cout<<'r', g[2]--;
if(g[3]) cout<<'i', g[3]--;
if(g[4]) cout<<'n', g[4]--;
if(g[5]) cout<<'g', g[5]--;
}
return 0;
}