File tree 1 file changed +56
-0
lines changed
1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < vector>
3
+ #include < string>
4
+ #include < algorithm>
5
+
6
+ using namespace std ;
7
+
8
+ void swap (int & a, int & b){
9
+ int temp = a;
10
+ a = b;
11
+ b = temp;
12
+ }
13
+
14
+ int main () {
15
+ int test;
16
+ cin >> test;
17
+
18
+ while (test){
19
+ string s;
20
+ cin >> s;
21
+
22
+ int n = s.size (), mini = 10 , ind = -1 ;
23
+
24
+ vector<int > temp (n);
25
+
26
+ for (int i = 0 ; i < n; i++){
27
+ int num = s[i] - ' 0' ;
28
+ temp[i] = num;
29
+
30
+ if (num%2 == 0 ){
31
+ if (num < mini){
32
+ mini = num;
33
+ ind = i;
34
+ }
35
+ }
36
+ }
37
+
38
+ if (ind == -1 ){
39
+ sort (temp.begin (), temp.end ());
40
+ }
41
+ else {
42
+ swap (temp[0 ], temp[ind]);
43
+ sort (temp.begin ()+1 , temp.end ());
44
+ }
45
+
46
+ for (int i = n-1 ; i >= 0 ; i--){
47
+ cout << temp[i];
48
+ }
49
+
50
+ cout << endl;
51
+
52
+ test--;
53
+ }
54
+
55
+ return 0 ;
56
+ }
You can’t perform that action at this time.
0 commit comments