1043 想法有待实现

来源:互联网 发布:java equals int 编辑:程序博客网 时间:2024/06/04 18:55
//自己写一个排序,然后按照PPAATTeesstt
//直接写patest的排序然后输出




#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <sstream>
#include <iomanip>
#include <cmath>
#include<limits>
#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
string a;
cin>>a;
int len=a.length();
int b[6]={0};
sort(a.begin(),a.end());
for(int i=0;i<len;i++)
{
if(a[i]=='P') b[0]++;
else if(a[i]=='A') b[1]++;
else if(a[i]=='T') b[2]++;
else if(a[i]=='e') b[3]++;
else if(a[i]=='s') b[4]++;
else if(a[i]=='t') b[5]++;


}
int max = b[0];
    for (int i = 1; i < 6; i++) {
        if (b[i] > max) {
            max = b[i];
        }
    }
  for (int i = 0; i < max; i++) 
{
if(b[0]!=0) {cout<<'P';b[0]--;}
if(b[1]!=0) {cout<<'A';b[1]--;}
if(b[2]!=0) {cout<<'T';b[2]--;}
if(b[3]!=0) {cout<<'e';b[3]--;}
if(b[4]!=0) {cout<<'s';b[4]--;}
if(b[5]!=0){ cout<<'t';b[5]--;}
}


return 0;
}









0 0
原创粉丝点击