給定一個(gè)長度不超過10000的、僅由英文字母構(gòu)成的字符串。請(qǐng)將字符重新調(diào)整順序,按“PATestPATest….”這樣的順序輸出,并忽略其它字符。當(dāng)然,六種字符的個(gè)數(shù)不一定是一樣多的,若某種字符已經(jīng)輸出完,則余下的字符仍按PATest的順序打印,直到所有字符都被輸出。
輸入格式:
輸入在一行中給出一個(gè)長度不超過10000的、僅由英文字母構(gòu)成的非空字符串。
輸出格式:
在一行中按題目要求輸出排序后的字符串。題目保證輸出非空。
輸入樣例: 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;}
|
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注