水题。还是一道hash题。
#include<iostream> using namespace std; int main() { int map[128] = {0}; char c; while (scanf("%c",&c) != 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; }
原文地址:https://www.cnblogs.com/keep23456/p/12332468.html
时间: 2024-10-30 05:00:13