[PAT乙级]1043 输出PATest
生活随笔
收集整理的這篇文章主要介紹了
[PAT乙级]1043 输出PATest
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給定一個長度不超過 10?4?? 的、僅由英文字母構成的字符串。請將字符重新調整順序,按 PATestPATest… 這樣的順序輸出,并忽略其它字符。當然,六種字符的個數不一定是一樣多的,若某種字符已經輸出完,則余下的字符仍按 PATest 的順序打印,直到所有字符都被輸出。
輸入格式:
輸入在一行中給出一個長度不超過 10?4?? 的、僅由英文字母構成的非空字符串。
輸出格式:
在一行中按題目要求輸出排序后的字符串。題目保證輸出非空。
輸入樣例:
輸出樣例:
PATestPATestPTetPTePePee代碼如下:
#include <iostream> #include <string> using namespace std; const int N = 10; int cnt[N]; char c[] = { 'P','A','T','e','s','t' }; int main() {string str;cin >> str;for (int i = 0; i < str.length(); i++){if (str[i] == 'P') cnt[0]++;else if (str[i] == 'A') cnt[1]++;else if (str[i] == 'T') cnt[2]++;else if (str[i] == 'e') cnt[3]++;else if (str[i] == 's') cnt[4]++;else if (str[i] == 't') cnt[5]++;}while (cnt[0] || cnt[1] || cnt[2] || cnt[3] || cnt[4] || cnt[5]){for (int i = 0; i < 6; i++){if (cnt[i]){cout << c[i];cnt[i]--;}}}return 0; }總結
以上是生活随笔為你收集整理的[PAT乙级]1043 输出PATest的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [PAT乙级]1046 划拳
- 下一篇: 1099 元的小米智能门锁 E20 开启