給定一個長度不超過10000的、僅由英文字母構成的字符串。請將字符重新調整順序,按“PATestPATest….”這樣的順序輸出,并忽略其它字符。當然,六種字符的個數不一定是一樣多的,若某種字符已經輸出完,則余下的字符仍按PATest的順序打印,直到所有字符都被輸出。
輸入格式:
輸入在一行中給出一個長度不超過10000的、僅由英文字母構成的非空字符串。
輸出格式:
在一行中按題目要求輸出排序后的字符串。題目保證輸出非空。
輸入樣例: redlesPayBestPATTopTeephpereatitAPPT 輸出樣例: PATestPATestPTetPTePePee
#include <iostream>using namespace std;int Isempty(int* count , int n){ int flag = 1; for ( int i = 0 ; i < n ; i++){ if ( count[i] > 0 ){ flag = 0; break; } } return flag;}int main(){ string str; cin>>str; char letter[6]={'P','A','T','e','s','t'}; int count[6] = {0}; for ( int i = 0 ; i < str.length() ; i++){ if ( str[i] == 'P'){ count[0]++; } if ( str[i] == 'A'){ count[1]++; } if ( str[i] == 'T'){ count[2]++; } if ( str[i] == 'e'){ count[3]++; } if ( str[i] == 's'){ count[4]++; } if ( str[i] == 't'){ count[5]++; } } while (!Isempty(count,6)){ for ( int i = 0 ; i < 6 ; i++){ if ( count[i] != 0){ cout<<letter[i]; count[i]--; }else{ continue; } } } return 0;}新聞熱點
疑難解答