题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805280074743808
这题也很水,不过一开始我没设置times变量,用的hashtable[maxi],结果就是在输出的时候哈希表也在改变,最后少数出了几行;
代码
#include<iostream>#include<vector>#include<cctype>#include<cstring>#include<string>#include<algorithm>using namespace std;int main(){string input;string example = "PATest";vector<int> hashtable(6,0);getline(cin, input);for(int i = 0; i < input.size(); i++){if(example.find(input[i])!=string::npos){hashtable[example.find(input[i])]++;}}//取hashtable最大值int maxi = 0;for(int i = 0; i < 6; i++){if(hashtable[i]>=hashtable[maxi]) maxi = i;}int times = hashtable[maxi];for(int i = 0; i < times; i++){for(int j = 0; j < 6; j++){if(hashtable[j]!=0){printf("%c",example[j]);hashtable[j]--;}}}}
#include <iostream>using namespace std;int main() {int map[128] = {0}, c;while ((c = cin.get()) != EOF) map[c]++;while (map['P'] > 0 || map['A'] > 0 || map['T'] > 0 || map['e'] > 0 || map['s'] > 0 || map['t'] > 0) {if (map['P']-- > 0) cout << 'P';if (map['A']-- > 0) cout << 'A';if (map['T']-- > 0) cout << 'T';if (map['e']-- > 0) cout << 'e';if (map['s']-- > 0) cout << 's';if (map['t']-- > 0) cout << 't';}return 0;}
