Educational Codeforces Round 75 C.Minimize The Integer[思考]
8334 ワード
C. Minimize The Integer
https://codeforces.com/contest/1251/problem/Cこの问题は过ぎるのが遅すぎて自分で良い料理をあげましたあなたに1つの顺番の规则をあげました隣の交换しかできませんしかも交换は彼らのパリティが异なることを保证する必要がありますこのようにたとえ例を见てパリティに连络してすぐにパリティのデータと彼らの顺番が変わることができないことを见ることができますしかし异なるパリティのは胜手にこの问题を交换することができて水を始めました前に変えることができるのと今の异なっている偶数性の数は长い间书いてゆっくりとやっと発见して要らないことを発见します
https://codeforces.com/contest/1251/problem/Cこの问题は过ぎるのが遅すぎて自分で良い料理をあげましたあなたに1つの顺番の规则をあげました隣の交换しかできませんしかも交换は彼らのパリティが异なることを保证する必要がありますこのようにたとえ例を见てパリティに连络してすぐにパリティのデータと彼らの顺番が変わることができないことを见ることができますしかし异なるパリティのは胜手にこの问题を交换することができて水を始めました前に変えることができるのと今の异なっている偶数性の数は长い间书いてゆっくりとやっと発见して要らないことを発见します
#include
using namespace std;
const int maxn = 106 + 10;
int cas, n;
string str;
queue<char> o, e;
int main() {
cin >> cas;
while(cas --) {
cin >> str;
for(int i = 0; i < str.size(); i ++) {
if((str[i] - '0') % 2 == 1)
o.push(str[i]);
else
e.push(str[i]);
}
while(!o.empty() || !e.empty()) {
if(o.empty()) {
cout << e.front();
e.pop();
} else if(e.empty()) {
cout << o.front();
o.pop();
} else {
if(e.front() > o.front()) {
cout << o.front();
o.pop();
} else {
cout << e.front();
e.pop();
}
}
}
cout << endl;
//cout << str << endl;
}
return 0;
}