ファーウェイOJ中級問題-文字列の中で最も出現回数の少ない文字を削除します
575 ワード
削除文字列の中で最も出現回数の少ない文字を実現し、複数の文字が出現回数が同じであれば、すべて削除します.これらの単語を削除した文字列を出力し、文字列内の他の文字は元の順序を維持します.
void HWoj(){
string test = "aaaabbbcc",Outstr="";
int book[256] = { 0 };
int len = test.length(), mined=1;
for (int i = 0; i < len; ++i){
++book[test[i]];
}
mined = book[test[0]];
for (int i = 0; i < len; ++i){
if (book[test[i]] <= mined){
mined = book[test[i]];
}
}
for (int i = 0; i < len; ++i){
if (book[test[i]] > mined){ Outstr.push_back(test[i]); }
}
cout << Outstr << endl;
}