#include <bits/stdc++.h> #include<math.h> #include <string> using namespace std; const int MAX_LEN = 10005; char str[MAX_LEN]; int hashTable[30] = {0}; int main(){ cin>>str; int len = strlen(str); int count = 0; //map<char,int> result; for(int i =0;i<len;++i){ if(str[i] == 'P' || str[i] == 'A' || str[i] == 'T' || str[i] == 'e' || str[i] == 's' || str[i] == 't'){ count++; } } map<char,int> result; //vector<char> result[count]; for(int i =0;i<len;++i){ if(str[i] == 'P' || str[i] == 'A' || str[i] == 'T' || str[i] == 'e' || str[i] == 's' || str[i] == 't'){ result[str[i]]++; } } map<char,int>::iterator iter; /*while(count != 0){ }*/ /*for(iter = result.begin();iter != result.end();iter++){ if(iter->) }*/ for(int i =0;i<count;++i){ //map<char,int>::iterator iter; iter = result.begin(); for(;iter != result.end();++iter){ if(iter->first == 'P' && iter->second > 0){ cout<<iter->first; iter->second--; break; } } iter = result.begin(); for(;iter != result.end();++iter){ if(iter->first == 'A' && iter->second > 0){ cout<<iter->first; iter->second--; break; } } iter = result.begin(); for(;iter != result.end();++iter){ if(iter->first == 'T' && iter->second > 0){ cout<<iter->first; iter->second--; break; } } iter = result.begin(); for(;iter != result.end();++iter){ if(iter->first == 'e' && iter->second > 0){ cout<<iter->first; iter->second--; break; } } iter = result.begin(); for(;iter != result.end();++iter){ if(iter->first == 's' && iter->second > 0){ cout<<iter->first; iter->second--; break; } } iter = result.begin(); for(;iter != result.end();++iter){ if(iter->first == 't' && iter->second > 0){ cout<<iter->first; iter->second--; break; } } } system("pause"); return 0; }
来源:https://www.cnblogs.com/JasonPeng1/p/12161128.html