-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF_1251C.cpp
More file actions
63 lines (56 loc) · 802 Bytes
/
CF_1251C.cpp
File metadata and controls
63 lines (56 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <string>
#include <deque>
using namespace std;
void go() {
string num;
cin >> num;
deque<char> even;
deque<char> odd;
for (int i = 0; i < num.length(); i++)
{
if (num[i] % 2 == 0)
{
even.push_back(num[i]);
}
else
{
odd.push_back(num[i]);
}
}
string result = "";
while (!even.empty() && !odd.empty())
{
// 홀수를 넣는다.
if (even.front() > odd.front())
{
result += odd.front();
odd.pop_front();
}
else
{
result += even.front();
even.pop_front();
}
}
// 나머지 처리
while (!even.empty())
{
result += even.front();
even.pop_front();
}
while (!odd.empty())
{
result += odd.front();
odd.pop_front();
}
cout << result << endl;
}
int main() {
int t;
cin >> t;
while (t--)
{
go();
}
}