description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
s = input()
odd_seq, oi = [0] * len(s), 0
even_seq, ei = [0] * len(s), 0
for c in s:
v = int(c)
if v % 2 == 0:
even_seq[ei] = v
ei += 1
else:
odd_seq[oi] = v
oi += 1
res = ""
n, m = oi, ei
l, r = 0, 0
while l < n or r < m:
if l < n and r < m:
v = odd_seq[l]
if odd_seq[l] < even_seq[r]:
l += 1
else:
v = even_seq[r]
r += 1
res += str(v)
elif l < n:
res += str(odd_seq[l])
l += 1
else:
res += str(even_seq[r])
r += 1
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def solve1(s):
evens = [u for u in s if u % 2 == 0]
odds = [u for u in s if u % 2 == 1]
if len(odds) == 0:
return evens
ans = []
inserted_odd = 0
current_odd = odds[inserted_odd]
for i in range(len(evens)):
while current_odd < evens[i] and inserted_odd < len(odds):
ans.append(current_odd)
inserted_odd += 1
if inserted_odd < len(odds):
current_odd = odds[inserted_odd]
ans.append(evens[i])
while inserted_odd < len(odds):
ans.append(current_odd)
inserted_odd += 1
if inserted_odd < len(odds):
current_odd = odds[inserted_odd]
return ans
def solve2(s):
odds = [u for u in s if u % 2 == 0]
evens = [u for u in s if u % 2 == 1]
if len(odds) == 0:
return evens
ans = []
inserted_odd = 0
current_odd = odds[inserted_odd]
for i in range(len(evens)):
while current_odd < evens[i] and inserted_odd < len(odds):
ans.append(current_odd)
inserted_odd += 1
if inserted_odd < len(odds):
current_odd = odds[inserted_odd]
ans.append(evens[i])
while inserted_odd < len(odds):
ans.append(current_odd)
inserted_odd += 1
if inserted_odd < len(odds):
current_odd = odds[inserted_odd]
return ans
for _ in range(int(input())):
s = list(map(int, list(input())))
ans = min(solve1(s), solve2(s))
print("".join(map(str, ans)))
|
FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for tt in range(t):
s = input().strip()
even = []
odd = []
for i in s:
if int(i) % 2 == 0:
even.append(int(i))
else:
odd.append(int(i))
ans = ""
i = 0
j = 0
while i < len(even) and j < len(odd):
if even[i] <= odd[j]:
ans += str(even[i])
i += 1
else:
ans += str(odd[j])
j += 1
while i < len(even):
ans += str(even[i])
i += 1
while j < len(odd):
ans += str(odd[j])
j += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def run_testcase():
digits = [int(x) for x in input()]
odds = list(filter(lambda x: x % 2 == 1, digits))
evens = list(filter(lambda x: x % 2 == 0, digits))
smallest = []
i = 0
j = 0
while i < len(odds) and j < len(evens):
if odds[i] < evens[j]:
smallest.append(odds[i])
i += 1
else:
smallest.append(evens[j])
j += 1
smallest += odds[i:]
smallest += evens[j:]
return "".join(str(x) for x in smallest)
testcase_count = int(input())
for i in range(testcase_count):
print(str(run_testcase()))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def li():
return [int(i) for i in input()]
for _ in range(int(input())):
l = li()
a = []
b = []
for i in l:
if i & 1:
a.append(i)
else:
b.append(i)
ans = []
i = j = 0
while i < len(a) and j < len(b):
if a[i] < b[j]:
ans.append(a[i])
i += 1
else:
ans.append(b[j])
j += 1
ans += a[i:]
ans += b[j:]
print("".join(str(k) for k in ans))
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
word = list(map(str, input()))
even, odd = [], []
for i in word:
if int(i) % 2 == 0:
even.append(i)
else:
odd.append(i)
ans = []
l, r = 0, 0
while l < len(even) and r < len(odd):
if even[l] < odd[r]:
ans.append(even[l])
l += 1
else:
ans.append(odd[r])
r += 1
ans += even[l:]
ans += odd[r:]
print("".join(ans))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input().strip())
for i in range(t):
s = input().strip()
odd = [int(c) for c in s if int(c) % 2 != 0]
even = [int(c) for c in s if int(c) % 2 == 0]
i, j = 0, 0
out = ""
while i < len(odd) or j < len(even):
if i == len(odd):
out += str(even[j])
j += 1
elif j == len(even):
out += str(odd[i])
i += 1
elif odd[i] > even[j]:
out += str(even[j])
j += 1
else:
out += str(odd[i])
i += 1
print(out)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
q = int(input())
arr = []
for _ in range(q):
s = input()
a = [int(x) for x in s]
l = []
c = []
ans = []
for i, x in enumerate(a):
if x % 2 == 0:
c.append(x)
else:
l.append(x)
i, j = 0, 0
while i < len(l) and j < len(c):
if l[i] < c[j]:
ans.append(l[i])
i += 1
else:
ans.append(c[j])
j += 1
while i < len(l):
ans.append(l[i])
i += 1
while j < len(c):
ans.append(c[j])
j += 1
arr.append("".join([str(x) for x in ans]))
print("\n".join([x for x in arr]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
T = int(input())
results = []
for _ in range(T):
msg = input()
odds = []
evens = []
for c in msg:
if int(c) % 2 == 0:
evens.append(c)
else:
odds.append(c)
i = j = 0
out = []
while i < len(odds) and j < len(evens):
if int(odds[i]) < int(evens[j]):
out.append(odds[i])
i += 1
else:
out.append(evens[j])
j += 1
while i < len(odds):
out.append(odds[i])
i += 1
while j < len(evens):
out.append(evens[j])
j += 1
results.append("".join(out))
for i in results:
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
while n:
n -= 1
s = input()
oddq = []
evenq = []
sf = []
i = 0
while i < len(s):
if not int(s[i]) % 2:
evenq.append(s[i])
else:
oddq.append(s[i])
i += 1
i = 0
j = 0
while i < len(oddq) and j < len(evenq):
if oddq[i] < evenq[j]:
sf.append(oddq[i])
i += 1
else:
sf.append(evenq[j])
j += 1
sf += oddq[i:] + evenq[j:]
print("".join(sf))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
foo = []
n = int(input())
for i in range(n):
s = []
ss = input()
for j in ss:
s.append(j)
a = ""
d = []
f = []
for q in s:
if int(q) % 2 == 0:
d.append(q)
else:
f.append(q)
di = 0
fi = 0
d.append(11)
f.append(11)
for j in range(len(s)):
if int(d[di]) > int(f[fi]):
a += f[fi]
fi += 1
else:
a += d[di]
di += 1
foo.append(a)
for i in foo:
print(i)
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for itr in range(int(input())):
a = list(map(int, list(input())))
even = []
odd = []
for i in range(len(a)):
if a[i] % 2:
odd.append(a[i])
else:
even.append(a[i])
ans = []
i = 0
j = 0
while i < len(even) and j < len(odd):
if even[i] < odd[j]:
ans.append(even[i])
i += 1
else:
ans.append(odd[j])
j += 1
while i < len(even):
ans.append(even[i])
i += 1
while j < len(odd):
ans.append(odd[j])
j += 1
for i in ans:
print(i, end="")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
a = list(input())
n = len(a)
odd = []
even = []
for i in range(n):
a[i] = int(a[i])
if a[i] % 2 == 0:
odd.append(a[i])
else:
even.append(a[i])
lo = len(odd)
le = len(even)
oi = 0
ei = 0
while oi < lo and ei < le:
if odd[oi] < even[ei]:
print(odd[oi], end="")
oi += 1
else:
print(even[ei], end="")
ei += 1
for i in range(oi, lo):
print(odd[i], end="")
for i in range(ei, le):
print(even[i], end="")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
s = input()
n = len(s)
o = ""
e = ""
lo = 0
le = 0
for i in range(n):
if int(s[i]) % 2:
o += s[i]
lo += 1
else:
e += s[i]
le += 1
if lo == 0 or le == 0:
ans = o + e
else:
ans = ""
mi = min(lo, le)
i = 0
j = 0
while i < le and j < lo:
if e[i] < o[j]:
ans += e[i]
i += 1
else:
ans += o[j]
j += 1
ans += e[i:]
ans += o[j:]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
num = list(map(int, input().strip()))
odd = []
evn = []
for i in num:
if i % 2 == 0:
odd += [i]
else:
evn += [i]
ans = []
i = 0
j = 0
while len(ans) != len(num):
if i == len(odd):
ans += [str(evn[j])]
j += 1
elif j == len(evn):
ans += [str(odd[i])]
i += 1
elif odd[i] < evn[j]:
ans += [str(odd[i])]
i += 1
else:
ans += [str(evn[j])]
j += 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR LIST FUNC_CALL VAR VAR VAR VAR NUMBER VAR LIST FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
a = list(map(int, list(input())))
b = [i for i in a if i % 2 == 0]
c = [i for i in a if i % 2 == 1]
ind = 0
ind2 = 0
ans = []
while ind < len(b) and ind2 < len(c):
if b[ind] < c[ind2]:
ans.append(b[ind])
ind += 1
else:
ans.append(c[ind2])
ind2 += 1
if ind < len(b):
ans += b[ind:]
if ind2 < len(c):
ans += c[ind2:]
for i in ans:
print(i, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
resAr = []
for z in range(t):
nums = [int(i) for i in input()]
eNums = []
oNums = []
eC, oC = 0, 0
for i in nums:
if i % 2 == 0:
eNums.append(i)
eC += 1
else:
oNums.append(i)
oC += 1
i, j = 0, 0
rS = []
while i < eC and j < oC:
if eNums[i] < oNums[j]:
rS.append(str(eNums[i]))
i += 1
else:
rS.append(str(oNums[j]))
j += 1
while i < eC:
rS.append(str(eNums[i]))
i += 1
while j < oC:
rS.append(str(oNums[j]))
j += 1
resAr.append(rS)
for i in resAr:
print("".join(i))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for x in range(int(input())):
l = list(map(int, input()))
a = []
b = []
for i in range(len(l)):
if l[i] % 2:
a.append(l[i])
else:
b.append(l[i])
a.append(10)
b.append(10)
i = j = 0
k = ""
while i + j < len(l):
if a[i] < b[j]:
k += str(a[i])
i += 1
else:
k += str(b[j])
j += 1
print(k)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for test in range(t):
numS = input()
num = []
for e in numS:
num.append(int(e))
pares = []
impares = []
for i in range(len(num) - 1, -1, -1):
e = num[i]
if e % 2 == 0:
pares.append(e)
else:
impares.append(e)
ans = []
i1 = len(pares) - 1
i2 = len(impares) - 1
while i1 >= 0 and i2 >= 0:
ans.append(min(pares[i1], impares[i2]))
if ans[-1] == pares[i1]:
pares.pop()
i1 -= 1
else:
impares.pop()
i2 -= 1
while i1 >= 0:
ans.append(pares[i1])
i1 -= 1
while i2 >= 0:
ans.append(impares[i2])
i2 -= 1
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for __ in range(int(input())):
a = list(map(int, input()))
ar1 = []
ar2 = []
for elem in a:
if elem % 2 == 0:
ar1.append(elem)
else:
ar2.append(elem)
ans = []
i = 0
j = 0
while i < len(ar1) and j < len(ar2):
if ar1[i] < ar2[j]:
ans.append(ar1[i])
i += 1
else:
ans.append(ar2[j])
j += 1
if i < len(ar1):
for h in range(i, len(ar1)):
ans.append(ar1[h])
if j < len(ar2):
for h in range(j, len(ar2)):
ans.append(ar2[h])
print("".join(map(str, ans)))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
while t:
s = input()
a, b = [], []
for i in s:
if int(i) % 2:
a.append(i)
else:
b.append(i)
i = j = 0
while i < len(a) and j < len(b):
if a[i] < b[j]:
print(a[i], end="")
i += 1
else:
print(b[j], end="")
j += 1
while i < len(a):
print(a[i], end="")
i += 1
while j < len(b):
print(b[j], end="")
j += 1
print()
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
tests = int(input())
for _ in range(tests):
x = input()
ods = []
evens = []
for c in x:
if c == "1" or c == "3" or c == "5" or c == "7" or c == "9":
ods.append(c)
else:
evens.append(c)
ans = []
i = 0
j = 0
while i < len(ods) and j < len(evens):
if ods[i] < evens[j]:
ans.append(ods[i])
i += 1
else:
ans.append(evens[j])
j += 1
while i < len(ods):
ans.append(ods[i])
i += 1
while j < len(evens):
ans.append(evens[j])
j += 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR STRING VAR STRING VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def minimize(number):
odd, even = [], []
for i in number:
if i % 2 == 1:
odd.append(i)
else:
even.append(i)
odd.reverse()
even.reverse()
ans = []
while odd and even:
if odd[-1] < even[-1]:
ans.append(odd.pop())
else:
ans.append(even.pop())
if odd:
ans.extend(reversed(odd))
else:
ans.extend(reversed(even))
return "".join([str(i) for i in ans])
q = int(input())
for _ in range(q):
number = map(int, list(input()))
print(minimize(number))
|
FUNC_DEF ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for i in range(int(input())):
s = input()
ans = ""
e = list(filter(lambda i: int(i) % 2 == 1, s))
o = list(filter(lambda i: int(i) % 2 == 0, s))
i = j = 0
while i < len(e) or j < len(o):
if len(e) == i:
ans += o[j]
j += 1
continue
if len(o) == j:
ans += e[i]
i += 1
continue
if o[j] < e[i]:
ans += o[j]
j += 1
else:
ans += e[i]
i += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
l = []
for _ in range(int(input())):
n = list(map(int, list(input())))
odd = []
even = []
for i in n:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
odd.reverse()
even.reverse()
while len(odd) > 0 and len(even) > 0:
if odd[-1] < even[-1]:
print(odd[-1], end="")
odd.pop()
else:
print(even[-1], end="")
even.pop()
if len(odd) > 0:
odd.reverse()
print("".join(list(map(str, odd))))
if len(even) > 0:
even.reverse()
print("".join(list(map(str, even))))
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
MOD = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: list(map(int, input().split()))
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
for _ in range(ii()):
s = si()
eve = []
odd = []
for i in s:
if int(i) % 2 == 0:
eve.append(int(i))
else:
odd.append(int(i))
i = 0
j = 0
ans = []
while i < len(eve) and j < len(odd):
if eve[i] < odd[j]:
ans.append(eve[i])
i += 1
else:
ans.append(odd[j])
j += 1
ans.extend(odd[j:])
ans.extend(eve[i:])
for i in ans:
print(i, end="")
print()
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
T = int(input())
for t in range(T):
s = str(input())
n = len(s)
even = []
odd = []
arr = []
for i in range(n):
if int(s[i]) % 2 == 0:
even.append(int(s[i]))
else:
odd.append(int(s[i]))
j = 0
k = 0
for i in range(n):
if j == len(odd):
arr.append(even[k])
k += 1
continue
if k == len(even):
arr.append(odd[j])
j += 1
continue
if odd[j] < even[k]:
arr.append(odd[j])
j += 1
else:
arr.append(even[k])
k += 1
for i in range(n):
print(arr[i], end="")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def solve():
s = input()
evens = []
odds = []
for c in s:
i = int(c)
if i % 2 == 0:
evens.append(i)
else:
odds.append(i)
i, j = 0, 0
final = []
while True:
if i == len(evens):
final += odds[j:]
break
elif j == len(odds):
final += evens[i:]
break
elif evens[i] < odds[j]:
final.append(evens[i])
i += 1
else:
final.append(odds[j])
j += 1
print("".join(map(str, final)))
n = int(input())
for _ in range(n):
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def fun():
s = input()
odd = []
even = []
for i in s:
if int(i) % 2 == 0:
odd.append(i)
else:
even.append(i)
l = 0
r = 0
odd_n = len(odd)
even_n = len(even)
while l < odd_n and r < even_n:
if odd[l] < even[r]:
print(odd[l], end="")
l = l + 1
else:
print(even[r], end="")
r = r + 1
if l < odd_n:
while l < odd_n:
print(odd[l], end="")
l = l + 1
if r < even_n:
while r < even_n:
print(even[r], end="")
r = r + 1
print()
t = int(input())
while t != 0:
fun()
t = t - 1
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(0, t):
s = [i for i in input()]
ee = []
oo = []
ans = []
for i in s:
if int(i) & 1:
oo += [i]
else:
ee += [i]
o, e = 0, 0
while o < len(oo) and e < len(ee):
if oo[o] < ee[e]:
ans += [oo[o]]
o += 1
else:
ans += [ee[e]]
e += 1
ans += ee[e:] + oo[o:]
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR LIST VAR VAR VAR NUMBER VAR LIST VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
s = input()
e = []
o = []
for i in s:
if int(i) % 2 == 0:
e.append(int(i))
else:
o.append(int(i))
i = 0
j = 0
ans = ""
while i < len(e) or j < len(o):
if i == len(e):
ans += str(o[j])
j += 1
continue
if j == len(o):
ans += str(e[i])
i += 1
continue
if e[i] < o[j]:
ans += str(e[i])
i += 1
else:
ans += str(o[j])
j += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def solve(s):
e = []
o = []
for i in range(len(s)):
if s[i] % 2 == 0:
e.append(s[i])
else:
o.append(s[i])
i, j = 0, 0
res = []
while i < len(e) and j < len(o):
if e[i] < o[j]:
res.append(e[i])
i += 1
else:
res.append(o[j])
j += 1
if i == len(e):
left = o[j : len(o)]
else:
left = e[i : len(e)]
res = "".join(map(str, res)) + "".join(map(str, left))
print(res)
t = int(input())
for _ in range(t):
s = list(input())
s = list(map(int, s))
solve(s)
|
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
a = list(map(int, list(input())))
evens = []
odds = []
for val in a:
if val & 1:
odds.append(val)
else:
evens.append(val)
ans = []
n = len(evens)
m = len(odds)
i = 0
j = 0
while i < n and j < m:
if evens[i] < odds[j]:
ans.append(evens[i])
i += 1
else:
ans.append(odds[j])
j += 1
if i == n:
ans.extend(odds[j:])
else:
ans.extend(evens[i:])
print("".join(map(str, ans)))
|
IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
t = int(sys.stdin.readline())
for _ in range(t):
s = sys.stdin.readline()[:-1]
even = []
odd = []
n = len(s)
for i in range(n):
if int(s[i]) % 2 == 0:
even.append(s[i])
else:
odd.append(s[i])
i, j = 0, 0
ans = [(0) for _ in range(n)]
k = 0
e, o = len(even), len(odd)
while i < e and j < o:
if even[i] < odd[j]:
ans[k] = even[i]
k += 1
i += 1
else:
ans[k] = odd[j]
k += 1
j += 1
while i < e:
ans[k] = even[i]
k += 1
i += 1
while j < o:
ans[k] = odd[j]
k += 1
j += 1
print("".join(str(x) for x in ans))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
def rint():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().rstrip("\n")
def oint():
return int(input())
t = oint()
for _ in range(t):
even = []
odd = []
a = input()
for i in range(len(a)):
ai = int(a[i])
if ai % 2:
odd.append(ai)
else:
even.append(ai)
ee = len(even)
oe = len(odd)
oi = 0
ei = 0
ans = []
while ei < ee or oi < oe:
if ei == ee:
for i in range(oi, oe):
ans.append(str(odd[i]))
break
if oi == oe:
for i in range(ei, ee):
ans.append(str(even[i]))
break
if odd[oi] > even[ei]:
ans.append(str(even[ei]))
ei += 1
else:
ans.append(str(odd[oi]))
oi += 1
print("".join(map(str, ans)))
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = float("inf")
MOD = 10**9 + 7
for _ in range(INT()):
A = list(map(int, list(input())))
N = len(A)
odd = []
even = []
for a in A:
if a % 2 == 0:
even.append(a)
else:
odd.append(a)
odd = odd[::-1]
even = even[::-1]
ans = []
while odd and even:
if odd[-1] < even[-1]:
ans.append(odd.pop())
else:
ans.append(even.pop())
while odd:
ans.append(odd.pop())
while even:
ans.append(even.pop())
ans = list(map(str, ans))
print("".join(ans))
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for p in range(t):
n = input()
even = []
odd = []
for d in n:
if int(d) % 2 == 0:
even.append(d)
else:
odd.append(d)
i = 0
j = 0
ans = []
while i < len(even) and j < len(odd):
if even[i] < odd[j]:
ans.append(even[i])
i += 1
else:
ans.append(odd[j])
j += 1
if i < len(even):
while i != len(even):
ans.append(even[i])
i += 1
elif j < len(odd):
while j != len(odd):
ans.append(odd[j])
j += 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for i in range(t):
nums = list(map(int, list(input())))
nums0, nums1 = [], []
for num in nums:
if num % 2 == 0:
nums0.append(str(num))
else:
nums1.append(str(num))
nums0.append(str(99))
nums1.append(str(99))
p0, p1 = 0, 0
l0, l1 = len(nums0) - 1, len(nums1) - 1
ans = str()
while p0 < l0 or p1 < l1:
p0_prev = p0
while p0 < l0 and nums0[p0] < nums1[p1]:
p0 += 1
ans += "".join(nums0[p0_prev:p0])
p1_prev = p1
while p1 < l1 and nums1[p1] < nums0[p0]:
p1 += 1
ans += "".join(nums1[p1_prev:p1])
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
te = int(input())
while te > 0:
te -= 1
num = list(input())
n = len(num)
evens = []
odds = []
for i in num:
if int(i) & 1 == 1:
odds.append(i)
else:
evens.append(i)
ans = ""
i = 0
j = 0
while i < len(evens) and j < len(odds):
if int(evens[i]) < int(odds[j]):
ans += evens[i]
i += 1
else:
ans += odds[j]
j += 1
if i == len(evens):
while j < len(odds):
ans += odds[j]
j += 1
elif j == len(odds):
while i < len(evens):
ans += evens[i]
i += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for i in range(int(input())):
s = input()
even = []
odd = []
for j in s:
t = int(j)
if t % 2 == 0:
even.append(t)
else:
odd.append(t)
a = 0
b = 0
s1 = ""
while a < len(even) and b < len(odd):
if even[a] < odd[b]:
s1 += str(even[a])
a += 1
else:
s1 += str(odd[b])
b += 1
if a == len(even):
for j in range(b, len(odd)):
s1 += str(odd[j])
else:
for j in range(a, len(even)):
s1 += str(even[j])
print(s1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
k = int(input())
r = []
for _ in " " * k:
(*s,) = list(input())
e = []
o = []
t = ""
for i in s:
if int(i) % 2 == 0:
e += [i]
else:
o += [i]
i = 0
j = 0
while i < len(e) and j < len(o):
if e[i] < o[j]:
print(e[i], end="")
i += 1
else:
print(o[j], end="")
j += 1
while i < len(e):
print(e[i], end="")
i += 1
while j < len(o):
print(o[j], end="")
j += 1
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR BIN_OP STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR LIST VAR VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
a = [int(i) for i in input()]
n = len(a)
even = [i for i in a if not i & 1]
odd = [i for i in a if i & 1]
even = even[::-1]
odd = odd[::-1]
res = ""
while len(res) < n:
if even and odd:
nxt = min(even[-1], odd[-1])
res += str(nxt)
if nxt == even[-1]:
even.pop()
else:
odd.pop()
elif even:
nxt = even[-1]
res += str(nxt)
even.pop()
else:
nxt = odd[-1]
res += str(nxt)
odd.pop()
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING WHILE FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
q = int(input())
for _ in range(q):
s = list(input())
n = len(s)
even = []
odd = []
for i in range(n):
s[i] = int(s[i])
if s[i] % 2 == 0:
even.append(s[i])
else:
odd.append(s[i])
i = 0
j = 0
ans = []
while i < len(even) and j < len(odd):
if even[i] < odd[j]:
ans.append(even[i])
i += 1
else:
ans.append(odd[j])
j += 1
if i < len(even):
k = i
for i in range(k, len(even)):
ans.append(even[i])
else:
k = j
for i in range(k, len(odd)):
ans.append(odd[i])
for i in range(n):
ans[i] = str(ans[i])
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
x = list(input())
chet, nechet = [], []
for i in x:
if int(i) % 2 == 0:
chet.append(int(i))
else:
nechet.append(int(i))
c, n, lnc, lnn = 0, 0, len(chet), len(nechet)
while c != lnc or n != lnn:
if c == lnc:
k = nechet[n]
n += 1
elif n == lnn:
k = chet[c]
c += 1
elif nechet[n] < chet[c]:
k = nechet[n]
n += 1
else:
k = chet[c]
c += 1
print(k, end="")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
T = int(input())
for t in range(T):
a = str(input())
a_even = ""
a_odd = ""
minimized_a = ""
for x in a:
if int(x) % 2 == 0:
a_even += x
else:
a_odd += x
index_even = 0
index_odd = 0
while index_even < len(a_even) or index_odd < len(a_odd):
if index_even >= len(a_even):
minimized_a += a_odd[index_odd:]
break
elif index_odd >= len(a_odd):
minimized_a += a_even[index_even:]
break
elif a_even[index_even] < a_odd[index_odd]:
minimized_a += a_even[index_even]
index_even += 1
elif a_even[index_even] > a_odd[index_odd]:
minimized_a += a_odd[index_odd]
index_odd += 1
print(minimized_a)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
for qu in range(T):
S = list(map(ord, readline().strip()))
SE = []
SO = []
for s in S:
if s % 2 == 0:
SE.append(s)
else:
SO.append(s)
LE = len(SE)
LO = len(SO)
inf = 10000
SE.append(inf)
SO.append(inf)
cnte = 0
cnto = 0
ans = []
for _ in range(LE + LO):
if SE[cnte] < SO[cnto]:
ans.append(SE[cnte])
cnte += 1
else:
ans.append(SO[cnto])
cnto += 1
Ans[qu] = ans
for a in Ans:
sys.stdout.write("".join(map(chr, a)))
sys.stdout.write("\n")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
s = input()
e = []
o = []
for i in s:
x = int(i)
if x % 2 == 0:
e.append(x)
else:
o.append(x)
e = e[::-1]
o = o[::-1]
z = []
while len(o) > 0 and len(e) > 0:
if e[-1] < o[-1]:
g = e.pop()
else:
g = o.pop()
z.append(str(g))
while len(o) > 0:
g = o.pop()
z.append(str(g))
while len(e) > 0:
g = e.pop()
z.append(str(g))
r = "".join(z)
print(r)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
q = int(input())
for u in range(q):
ans = ""
od = ""
ev = ""
s = input()
for i in s:
d = ord(i) - 48
if d % 2 == 0:
ev += i
else:
od += i
odsz = len(od)
evsz = len(s) - odsz
cod = 0
cev = 0
while cod < odsz and cev < evsz:
if ev[cev] < od[cod]:
ans += ev[cev]
cev += 1
else:
ans += od[cod]
cod += 1
while cod < odsz:
ans += od[cod]
cod += 1
while cev < evsz:
ans += ev[cev]
cev += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
q = int(input())
inputlist = []
for j in range(q):
m = str(input())
inputlist.append(m)
def minimize(strint):
intlist = []
for j in strint:
intlist.append(j)
evelist = []
oddlist = []
for j in intlist:
if int(j) % 2 == 0:
evelist.append(j)
else:
oddlist.append(j)
answerstr = ""
i = 0
j = 0
while i < len(evelist) and j < len(oddlist):
if int(evelist[i]) < int(oddlist[j]):
answerstr += str(evelist[i])
i += 1
else:
answerstr += str(oddlist[j])
j += 1
if i <= len(evelist) - 1:
for k in range(i, len(evelist)):
answerstr += str(evelist[k])
if j <= len(oddlist) - 1:
for k in range(j, len(oddlist)):
answerstr += str(oddlist[k])
return answerstr
for j in inputlist:
print(minimize(j))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def main():
lines = int(input())
for i in range(lines):
odd, even = list(), list()
result = ""
number = list(str(input()))
for letter in number:
buff = int(letter)
if buff % 2:
odd.append(letter)
else:
even.append(letter)
i, j = 0, 0
even_size, odd_size = len(even), len(odd)
while i < even_size or j < odd_size:
if i < even_size and j < odd_size:
if even[i] < odd[j]:
result += even[i]
i += 1
else:
result += odd[j]
j += 1
elif i < even_size:
result += even[i]
i += 1
else:
result += odd[j]
j += 1
print(result)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input(""))
for _ in range(t):
a = input("")
n = len(a)
o = []
e = []
for i in range(n):
if int(a[i]) % 2 == 0:
e.append(int(a[i]))
else:
o.append(int(a[i]))
ans = []
i = 0
j = 0
lo = len(o)
le = len(e)
while i < lo and j < le:
if o[i] < e[j]:
ans.append(o[i])
i = i + 1
else:
ans.append(e[j])
j = j + 1
if i == lo:
ans = ans + e[j:]
elif j == le:
ans = ans + o[i:]
for nu in ans:
print(nu, end="")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
odd_s = ["1", "3", "5", "7", "9"]
def is_odd(c):
return c in odd_s
T = int(input())
for _ in range(T):
s = input()
odd = list(filter(is_odd, s))
even = list(filter(lambda x: not is_odd(x), s))
ans = []
o = e = 0
while o < len(odd) and e < len(even):
if odd[o] < even[e]:
ans.append(odd[o])
o += 1
else:
ans.append(even[e])
e += 1
while o < len(odd):
ans.append(odd[o])
o += 1
while e < len(even):
ans.append(even[e])
e += 1
print("".join(ans))
|
ASSIGN VAR LIST STRING STRING STRING STRING STRING FUNC_DEF RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
string = input()
even = []
length = len(string)
odd = []
for i in string:
if int(i) % 2 == 0:
even.append(i)
else:
odd.append(i)
output = ""
i = 0
j = 0
l1 = len(even)
l2 = len(odd)
while i < l1 and j < l2:
if even[i] < odd[j]:
output += str(even[i])
i += 1
else:
output += str(odd[j])
j += 1
if i == l1:
output = output + "".join(odd[j:])
else:
output = output + "".join(even[i:])
print(output)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL STRING VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
from sys import stdin
def input():
return stdin.readline()[:-1]
def intput():
return int(input())
def sinput():
return input().split()
def intsput():
return map(int, sinput())
t = intput()
for _ in range(t):
a = input()
oddbuff = []
evenbuff = []
for x in a:
x = int(x)
if x % 2:
oddbuff.append(x)
else:
evenbuff.append(x)
result = []
oddx = 0
evenx = 0
while oddx < len(oddbuff) and evenx < len(evenbuff):
if oddbuff[oddx] < evenbuff[evenx]:
result.append(str(oddbuff[oddx]))
oddx += 1
else:
result.append(str(evenbuff[evenx]))
evenx += 1
for i in range(oddx, len(oddbuff)):
result.append(str(oddbuff[i]))
for i in range(evenx, len(evenbuff)):
result.append(str(evenbuff[i]))
print("".join(result))
|
FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
a = int(input())
for i in range(0, a):
arr = input()
arr = [int(i) for i in arr]
brr = [(i % 2) for i in arr]
even = []
odd = []
for i in arr:
if i % 2 == 1:
odd.append(i)
else:
even.append(i)
ans = []
ce = 0
co = 0
for i in range(0, len(arr)):
if ce >= len(even):
ans.append(odd[co])
co = co + 1
elif co >= len(odd):
ans.append(even[ce])
ce = ce + 1
elif even[ce] > odd[co]:
ans.append(odd[co])
co = co + 1
else:
ans.append(even[ce])
ce = ce + 1
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
even_digits = frozenset(str(n) for n in range(0, 9, 2))
odd_digits = frozenset(str(n) for n in range(1, 10, 2))
num_inputs = int(input())
for _ in range(num_inputs):
n = input()
evens = tuple(s for s in n if s in even_digits)
odds = tuple(s for s in n if s in odd_digits)
evens_len = len(evens)
odds_len = len(odds)
result = ""
even_index = 0
odd_index = 0
while True:
if even_index == evens_len:
sys.stdout.write("".join(odds[odd_index:]) + "\n")
break
elif odd_index == odds_len:
sys.stdout.write("".join(evens[even_index:]) + "\n")
break
if evens[even_index] < odds[odd_index]:
sys.stdout.write(evens[even_index])
even_index += 1
else:
sys.stdout.write(odds[odd_index])
odd_index += 1
sys.stdout.flush()
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
Q = int(input())
for q in range(Q):
s = input()
chet = []
nechet = []
for i in s:
if int(i) % 2 == 0:
chet.append(int(i))
else:
nechet.append(int(i))
chet.append(10)
nechet.append(10)
i = 0
j = 0
ans = []
while i < len(chet) and j < len(nechet):
if i == len(chet) - 1 and j == len(nechet) - 1:
break
if chet[i] < nechet[j]:
ans.append(chet[i])
i += 1
else:
ans.append(nechet[j])
j += 1
print(*ans, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
s = input()
odd = []
even = []
for l in s:
if int(l) % 2 == 0:
even.append(int(l))
else:
odd.append(int(l))
ans = []
el = 0
ol = 0
while el != len(even) and ol != len(odd):
a = even[el]
b = odd[ol]
if a < b:
ans.append(a)
el += 1
else:
ans.append(b)
ol += 1
if el == len(even):
ans = ans + odd[ol:]
else:
ans = ans + even[el:]
print("".join(map(str, ans)))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
from itertools import groupby
for _ in range(int(input())):
s = input()
n = len(s)
i = j = 0
while i < n or j < n:
while i < n and int(s[i]) % 2:
i += 1
while j < n and not int(s[j]) % 2:
j += 1
if i == j == n:
break
if i < n and (j == n or s[i] < s[j]):
print(end=s[i])
i += 1
else:
print(end=s[j])
j += 1
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR VAR VAR VAR WHILE VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
while n != 0:
n -= 1
res, pair, impair = "", "", ""
for i in input():
if int(i) % 2 == 0:
pair += i
else:
impair += i
a, b = 0, 0
while a < len(pair) and b < len(impair):
if pair[a] < impair[b]:
res += pair[a]
a += 1
else:
res += impair[b]
b += 1
for i in range(a, len(pair)):
res += pair[i]
for i in range(b, len(impair)):
res += impair[i]
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR STRING STRING STRING FOR VAR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for ic in range(t):
n = list(map(int, list(input().strip())))
odds, evens = [], []
for i in range(len(n) - 1, -1, -1):
if n[i] & 1:
odds.append(n[i])
else:
evens.append(n[i])
while odds and evens:
if odds[-1] < evens[-1]:
print(odds.pop(), end="")
else:
print(evens.pop(), end="")
while odds:
print(odds.pop(), end="")
while evens:
print(evens.pop(), end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR STRING WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
o = []
e = []
s = str(input())
a = [int(x) for x in s]
for i in a:
if i & 1:
o.append(i)
else:
e.append(i)
i = 0
j = 0
ans = []
n, m = len(o), len(e)
while i < n and j < m:
if o[i] < e[j]:
ans.append(o[i])
i += 1
else:
ans.append(e[j])
j += 1
while i < n:
ans.append(o[i])
i += 1
while j < m:
ans.append(e[j])
j += 1
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in [0] * int(input()):
l = x, y = [[], []]
i = j = 0
r = []
for d in input():
l[int(d) % 2] += (d,)
x += (":",)
y += (":",)
while x[i] + y[j] < "::":
if x[i] < y[j]:
r += (x[i],)
i += 1
else:
r += (y[j],)
j += 1
print("".join(r))
|
FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR LIST LIST LIST ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR STRING VAR STRING WHILE BIN_OP VAR VAR VAR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
input = lambda: sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
A = [int(a) for a in input()]
N = len(A)
O = []
E = []
for i in range(N):
if A[i] % 2:
O.append(A[i])
else:
E.append(A[i])
O = O[::-1]
E = E[::-1]
B = []
while O or E:
if not O:
B.append(E.pop())
elif not E:
B.append(O.pop())
elif O[-1] < E[-1]:
B.append(O.pop())
else:
B.append(E.pop())
print("".join(map(str, B)))
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
n = list(input())
odd = []
even = []
for i in range(len(n)):
if int(n[i]) % 2 == 0:
even.append(int(n[i]))
else:
odd.append(int(n[i]))
i, j = 0, 0
no = []
while i <= len(even) - 1 and j <= len(odd) - 1:
if even[i] < odd[j]:
no.append(even[i])
i += 1
else:
no.append(odd[j])
j += 1
if i == len(even):
for h in range(j, len(odd)):
no.append(odd[h])
else:
for h in range(i, len(even)):
no.append(even[h])
for k in no:
print(k, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
a = list(input())
evens = list()
odds = list()
answer = list()
for c in a:
if int(c) % 2 == 0:
evens.append(c)
else:
odds.append(c)
i, j = 0, 0
while i < len(evens) and j < len(odds):
if evens[i] < odds[j]:
answer.append(evens[i])
i += 1
else:
answer.append(odds[j])
j += 1
else:
answer.extend(evens[i:] + odds[j:])
print("".join(answer))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
while t > 0:
t = t - 1
li = [int(x) for x in input()]
ev = [x for x in li if x % 2 == 0]
odd = [x for x in li if x % 2 == 1]
lev = len(ev)
lodd = len(odd)
point_ev = 0
point_odd = 0
res = []
while point_ev < lev and point_odd < lodd:
if ev[point_ev] < odd[point_odd]:
res.append(ev[point_ev])
point_ev = point_ev + 1
else:
res.append(odd[point_odd])
point_odd = point_odd + 1
res.extend(ev[point_ev:])
res.extend(odd[point_odd:])
for ele in res:
print(ele, end="")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
for i in range(n):
s = input()
odds = []
evens = []
ans = []
for i in range(len(s)):
digi = ord(s[i]) - 48
if digi % 2 == 0:
evens.append(digi)
else:
odds.append(digi)
l1 = len(odds)
l2 = len(evens)
idx1 = 0
idx2 = 0
while idx1 < l1 and idx2 < l2:
if odds[idx1] < evens[idx2]:
ans.append(odds[idx1])
idx1 += 1
else:
ans.append(evens[idx2])
idx2 += 1
while idx1 < l1:
ans.append(odds[idx1])
idx1 += 1
while idx2 < l2:
ans.append(evens[idx2])
idx2 += 1
tmp = [str(i) for i in ans]
tmp = "".join(tmp)
print(tmp)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
from sys import stdin, stdout
for j in range(int(stdin.readline())):
even = []
odd = []
for i in input():
odd.append(ord(i) - 48) if (ord(i) - 48) % 2 else even.append(ord(i) - 48)
oc = 0
ec = 0
ol = len(odd)
el = len(even)
while oc < ol and ec < el:
if odd[oc] < even[ec]:
print(odd[oc], end="")
oc += 1
else:
print(even[ec], end="")
ec += 1
if oc == ol and ec != el:
for i in range(ec, el):
print(even[i], end="")
elif oc != ol and ec == el:
for i in range(oc, ol):
print(odd[i], end="")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
R = lambda: list(map(int, input().split()))
(q,) = R()
for w in range(q):
s = input()
n = len(s)
st1 = 0
st2 = 0
ch = []
nech = []
for i in s:
if int(i) % 2 == 0:
ch += [int(i)]
else:
nech += [int(i)]
ch += [100]
nech += [100]
for i in range(n):
if ch[st1] < nech[st2]:
print(ch[st1], end="")
st1 += 1
else:
print(nech[st2], end="")
st2 += 1
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR LIST FUNC_CALL VAR VAR VAR LIST FUNC_CALL VAR VAR VAR LIST NUMBER VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
a = input()
odd = []
even = []
for i in range(len(a)):
if int(a[i]) % 2 == 0:
even.append(int(a[i]))
else:
odd.append(int(a[i]))
ans = []
o_index = 0
e_index = 0
while o_index < len(odd) and e_index < len(even):
if odd[o_index] < even[e_index]:
ans.append(odd[o_index])
o_index += 1
else:
ans.append(even[e_index])
e_index += 1
if o_index < len(odd):
ans += odd[o_index:]
else:
ans += even[e_index:]
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
a = list(input())
b = []
s = []
i = 0
for x in a:
if i >= len(s) or (s[-1] in "02468") == (x in "02468"):
s += (x,)
else:
while i < len(s) and s[i] < x:
b += (s[i],)
i += 1
if i < len(s):
b += (x,)
else:
s += (x,)
b += s[i:]
print("".join(b))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER STRING VAR STRING VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
for t in range(n):
a = [int(c) for c in input()]
cur = 0
result = []
for i in range(1, len(a)):
if a[cur] & 1 == a[i] & 1:
continue
while cur < i:
if a[cur] < a[i]:
if a[cur] != -1:
result.append(str(a[cur]))
cur += 1
else:
result.append(str(a[i]))
a[i] = -1
break
for i in range(cur, len(a)):
if a[i] != -1:
result.append(str(a[i]))
print("".join(result))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
t = int(input())
for ti in range(t):
s = input()
odd = []
even = []
for c in s:
if int(c) % 2 == 0:
even.append(c)
else:
odd.append(c)
res = []
i = 0
j = 0
for _ in range(len(s)):
if i >= len(even):
res.append(odd[j])
j += 1
elif j >= len(odd):
res.append(even[i])
i += 1
elif odd[j] < even[i]:
res.append(odd[j])
j += 1
else:
res.append(even[i])
i += 1
print("".join(res))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
for i in range(n):
l = list(map(int, input()))
a = [k for k in l[::-1] if k % 2]
b = [k for k in l[::-1] if not k % 2]
ans = []
while a and b:
if a[-1] < b[-1]:
ans.append(a.pop())
else:
ans.append(b.pop())
if a:
ans.extend(a[::-1])
elif b:
ans.extend(b[::-1])
print("".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
def main():
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
N = input().rstrip("\n")
odd = []
even = []
for n_ in N:
n = int(n_)
if n % 2:
odd.append(n)
else:
even.append(n)
odd.reverse()
even.reverse()
ans = []
while True:
if len(odd) == 0:
even.reverse()
ans.extend(even)
break
elif len(even) == 0:
odd.reverse()
ans.extend(odd)
break
elif odd[-1] < even[-1]:
ans.append(odd.pop())
else:
ans.append(even.pop())
print("".join(map(str, ans)))
main()
|
IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
l = list(map(int, input()))
q1 = []
q2 = []
for t in l:
if t % 2:
q2.append(t)
else:
q1.append(t)
k1 = 0
k2 = 0
ans = []
while k1 < len(q1) and k2 < len(q2):
a = q1[k1]
b = q2[k2]
if a < b:
ans.append(a)
k1 += 1
else:
ans.append(b)
k2 += 1
for i in range(k1, len(q1)):
ans.append(q1[i])
for j in range(k2, len(q2)):
ans.append(q2[j])
print(*ans, sep="")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
from sys import stdin
def main():
data = stdin.read().splitlines()[1:]
for ii, s in enumerate(data):
gf, n = ([], []), len(s)
for c in s:
gf[ord(c) & 1].append(c)
g, f = gf
g.append("a")
f.append("a")
g.reverse()
f.reverse()
data[ii] = "".join(f.pop() if f[-1] < g[-1] else g.pop() for _ in range(n))
print("\n".join(map(str, data)))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
while t:
t -= 1
x = list(map(int, list(input())))
a = []
b = []
for i in x:
if i & 1:
b.append(i)
else:
a.append(i)
c = []
i = j = 0
m1 = len(a)
m2 = len(b)
while i < m1 and j < m2:
if a[i] < b[j]:
c.append(a[i])
i += 1
else:
c.append(b[j])
j += 1
while i < m1:
c.append(a[i])
i += 1
while j < m2:
c.append(b[j])
j += 1
print("".join(map(str, c)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
def getN():
return int(input())
def getList():
return list(map(int, input().split()))
def solve():
nums = [int(i) for i in input().strip()]
odds = []
evens = []
lodd, leven = 0, 0
for num in nums:
if num % 2 == 1:
odds.append(num)
lodd += 1
else:
evens.append(num)
leven += 1
odds.append(100)
evens.append(100)
io, ie = 0, 0
ans = []
while True:
if odds[io] < evens[ie]:
ans.append(odds[io])
io += 1
if io == lodd:
ans += evens[ie:leven]
break
else:
ans.append(evens[ie])
ie += 1
if ie == leven:
ans += odds[io:lodd]
break
print("".join(list(map(str, ans))))
return
def main():
t = getN()
for times in range(t):
solve()
main()
|
IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for i in range(t):
w = [int(k) for k in input()]
a, b = [], []
for j in w:
if j % 2 == 0:
a.append(j)
else:
b.append(j)
a = a[::-1]
b = b[::-1]
res = ""
c = len(w)
for j in range(c):
try:
if a[-1] < b[-1]:
res += str(a.pop())
else:
res += str(b.pop())
except:
if a:
for k in range(len(a)):
res += str(a.pop())
else:
for k in range(len(b)):
res += str(b.pop())
break
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for i in range(t):
s = list(input())
i = 0
odd = []
even = []
for i in s:
if int(i) % 2 == 0:
even.append(i)
else:
odd.append(i)
i = 0
j = 0
k = 0
m = ["" for i in range(len(s))]
while i < len(even) and j < len(odd):
if int(even[i]) < int(odd[j]):
m[k] = even[i]
k += 1
i += 1
else:
m[k] = odd[j]
k += 1
j += 1
while i < len(even):
m[k] = even[i]
k += 1
i += 1
while j < len(odd):
m[k] = odd[j]
k += 1
j += 1
print("".join(m))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
for _ in range(N):
S = input()[:-1]
odds = []
evens = []
for s in S:
if int(s) % 2 == 0:
evens.append(int(s))
else:
odds.append(int(s))
i_even = 0
i_odd = 0
ans = ""
while i_even < len(evens) and i_odd < len(odds):
if evens[i_even] >= odds[i_odd]:
ans += str(odds[i_odd])
i_odd += 1
else:
ans += str(evens[i_even])
i_even += 1
if i_even < len(evens):
for s in evens[i_even:]:
ans += str(s)
else:
for s in odds[i_odd:]:
ans += str(s)
print(ans)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
s = input()
o = []
e = []
for i in s:
if int(i) % 2 == 0:
e.append(i)
else:
o.append(i)
ans = []
x = 0
y = 0
while len(e) > x and len(o) > y:
if int(o[y]) > int(e[x]):
ans.append(e[x])
x += 1
else:
ans.append(o[y])
y += 1
print("".join(ans + o[y:] + e[x:]))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP VAR VAR VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
lst = []
n = int(input())
for i in range(n):
a = list(input())
lst2 = []
lst3 = []
lst4 = []
for i in range(len(a)):
if int(a[i]) % 2 == 0:
lst2.append(int(a[i]))
else:
lst3.append(int(a[i]))
i = 0
j = 0
while i != len(lst2) and j != len(lst3):
if lst2[i] < lst3[j]:
lst4.append(lst2[i])
i += 1
else:
lst4.append(lst3[j])
j += 1
while i != len(lst2):
lst4.append(lst2[i])
i += 1
while j != len(lst3):
lst4.append(lst3[j])
j += 1
lst.append(lst4)
for i in lst:
for j in i:
print(j, end="")
print()
|
ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
def main():
Ss = input()
ki = ""
gu = ""
for s in Ss:
if int(s) % 2 == 0:
gu += s
else:
ki += s
if len(gu) == 0:
return ki
elif len(ki) == 0:
return gu
else:
ans = ""
ind_gu = 0
ind_ki = 0
while ind_gu < len(gu) or ind_ki < len(ki):
if ind_gu == len(gu):
ans += ki[ind_ki]
ind_ki += 1
elif ind_ki == len(ki):
ans += gu[ind_gu]
ind_gu += 1
elif int(gu[ind_gu]) < int(ki[ind_ki]):
ans += gu[ind_gu]
ind_gu += 1
else:
ans += ki[ind_ki]
ind_ki += 1
return ans
for _ in range(n):
ans = main()
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
q = int(input())
for _ in range(q):
d = input()
a = []
b = []
for el in d:
n = int(el)
if n % 2 == 0:
a.append(n)
else:
b.append(n)
res = []
i = 0
j = 0
while i < len(a) and j < len(b):
if a[i] < b[j]:
res.append(str(a[i]))
i += 1
else:
res.append(str(b[j]))
j += 1
if i < len(a):
res.extend([str(e) for e in a[i:]])
else:
res.extend([str(e) for e in b[j:]])
print("".join(res))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
n = input()
odd = []
eve = []
for i in n:
if int(i) % 2 != 0:
odd.append(i)
else:
eve.append(i)
i = 0
j = 0
while i < len(odd) and j < len(eve):
if odd[i] < eve[j]:
print(odd[i], end="")
i += 1
else:
print(eve[j], end="")
j += 1
for k in range(i, len(odd)):
print(odd[k], end="")
for k in range(j, len(eve)):
print(eve[k], end="")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
a = input()
f, g = "", ""
for c in a:
if c in "13579":
f += c
else:
g += c
f += "a"
g += "a"
r = ""
i, j = 0, 0
while f[i] != "a" or g[j] != "a":
if f[i] < g[j]:
r += f[i]
i += 1
else:
r += g[j]
j += 1
print(r)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR STRING STRING FOR VAR VAR IF VAR STRING VAR VAR VAR VAR VAR STRING VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR VAR STRING VAR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
q = int(input())
for _ in range(q):
num = list(map(int, input()))
even = list(filter(lambda x: x % 2 == 0, num))
odd = list(filter(lambda x: x % 2 == 1, num))
if len(even) >= 1 and len(odd) >= 1:
output = []
e = 0
o = 0
while e < len(even) and o < len(odd):
if even[e] < odd[o]:
output.append(even[e])
e += 1
else:
output.append(odd[o])
o += 1
while e < len(even):
output.append(even[e])
e += 1
while o < len(odd):
output.append(odd[o])
o += 1
print("".join(map(str, output)))
else:
print("".join(map(str, num)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for t in range(int(input())):
s = input()
l = len(s)
eve = ""
odd = ""
for i in range(l):
if (ord(s[i]) - ord("0")) % 2 == 0:
eve += s[i]
else:
odd += s[i]
e0 = len(eve)
o0 = len(odd)
e = 0
o = 0
a = ""
for i in range(l):
if o == o0:
a += eve[e]
e += 1
elif e == e0:
a += odd[o]
o += 1
elif ord(eve[e]) > ord(odd[o]):
a += odd[o]
o += 1
else:
a += eve[e]
e += 1
print(a)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
s = list(map(int, list(input())))
even = []
odd = []
for i in s:
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
i = 0
j = 0
while i < len(even) and j < len(odd):
if even[i] < odd[j]:
i += 1
print(even[i - 1], end="")
else:
j += 1
print(odd[j - 1], end="")
while i < len(even):
i += 1
print(even[i - 1], end="")
while j < len(odd):
j += 1
print(odd[j - 1], end="")
print("")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING WHILE VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING WHILE VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
for _ in range(n):
num = list(map(int, list(input())))
odd = []
even = []
for n in num:
if n % 2 == 0:
even.append(n)
else:
odd.append(n)
m = len(odd)
n = len(even)
i = j = 0
res = []
while i < m and j < n:
if odd[i] < even[j]:
res.append(odd[i])
i += 1
else:
res.append(even[j])
j += 1
if i == m:
res += even[j:]
else:
res += odd[i:]
print("".join(list(map(str, res))))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
ev = []
od = []
s = map(int, list(input()))
for v in s:
if v % 2:
od.append(v)
else:
ev.append(v)
ev.append(1000)
od.append(1000)
ep = 0
op = 0
while ep < len(ev) - 1 or op < len(od) - 1:
if ev[ep] < od[op]:
print(ev[ep], end="")
ep += 1
else:
print(od[op], end="")
op += 1
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for i in range(0, t):
s = ""
d = ""
x = input()
for i in x:
c = int(i)
if c % 2 == 0:
s += i
else:
d += i
i = 0
j = 0
while i < len(s) and j < len(d):
if s[i] < d[j]:
print(s[i], end="")
i += 1
else:
print(d[j], end="")
j += 1
if i == len(s):
while j < len(d):
print(d[j], end="")
j += 1
else:
while i < len(s):
print(s[i], end="")
i += 1
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
for _ in range(int(input())):
arr = list(input())
even = []
odd = []
for i in arr:
i = int(i)
if i % 2 == 0:
even.append(i)
else:
odd.append(i)
i = 0
n = min(len(even), len(odd))
ans = []
e = 0
o = 0
while e < len(even) and o < len(odd):
if even[e] < odd[o]:
ans.append(even[e])
e += 1
else:
ans.append(odd[o])
o += 1
while e < len(even):
ans.append(even[e])
e += 1
while o < len(odd):
ans.append(odd[o])
o += 1
x = ""
for i in ans:
x += str(i)
print(x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for i2 in range(t):
ans = []
s = str(input())
even, odd = [], []
for i in range(len(s)):
if int(s[i]) % 2 == 0:
even.append(int(s[i]))
else:
odd.append(int(s[i]))
pointer = 0
for i in range(len(even)):
while pointer < len(odd) and odd[pointer] < even[i]:
ans.append(odd[pointer])
pointer += 1
ans.append(even[i])
for i in range(pointer, len(odd)):
ans.append(odd[i])
for i in ans:
print(i, end="")
print("")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
t = int(input())
for _ in range(t):
A = str(input())
A = list(A)
A = [int(d) for d in A]
n = len(A)
O = []
E = []
for a in A:
if a % 2 == 0:
E.append(a)
else:
O.append(a)
E.reverse()
O.reverse()
ans = []
while E and O:
e = E.pop()
o = O.pop()
if e < o:
ans.append(str(e))
O.append(o)
else:
ans.append(str(o))
E.append(e)
if E:
E.reverse()
for e in E:
ans += str(e)
if O:
O.reverse()
for o in O:
ans += str(o)
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
n = int(input())
for ewfe in range(n):
s = input()
par = []
npar = []
for i in s:
if int(i) % 2 == 0:
par.append(int(i))
else:
npar.append(int(i))
pa = 0
npa = 0
odp = []
while True:
if pa == len(par) and npa == len(npar):
break
if pa <= len(par) - 1 and npa <= len(npar) - 1:
if par[pa] < npar[npa]:
odp.append(par[pa])
pa += 1
else:
odp.append(npar[npa])
npa += 1
elif pa == len(par):
odp.append(npar[npa])
npa += 1
else:
odp.append(par[pa])
pa += 1
k = len(odp)
for i in range(k):
if i < k - 1:
print(odp[i], end="")
else:
print(odp[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE NUMBER IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR
|
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $2$).
For example, if $a = 032867235$ you can get the following integers in a single operation: $302867235$ if you swap the first and the second digits; $023867235$ if you swap the second and the third digits; $032876235$ if you swap the fifth and the sixth digits; $032862735$ if you swap the sixth and the seventh digits; $032867325$ if you swap the seventh and the eighth digits.
Note, that you can't swap digits on positions $2$ and $4$ because the positions are not adjacent. Also, you can't swap digits on positions $3$ and $4$ because the digits have the same parity.
You can perform any number (possibly, zero) of such operations.
Find the minimum integer you can obtain.
Note that the resulting integer also may contain leading zeros.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 10^4$) β the number of test cases in the input.
The only line of each test case contains the integer $a$, its length $n$ is between $1$ and $3 \cdot 10^5$, inclusive.
It is guaranteed that the sum of all values $n$ does not exceed $3 \cdot 10^5$.
-----Output-----
For each test case print line β the minimum integer you can obtain.
-----Example-----
Input
3
0709
1337
246432
Output
0079
1337
234642
-----Note-----
In the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $0 \underline{\textbf{70}} 9 \rightarrow 0079$.
In the second test case, the initial integer is optimal.
In the third test case you can perform the following sequence of operations: $246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$.
|
def count(s):
zero = 0
one = 0
for i in range(len(s)):
if s[i] == "0":
zero += 1
else:
one += 1
return zero, one
for t in range(int(input())):
n = input()
even = []
odd = []
for i in range(len(n)):
if int(n[i]) & 1:
odd.append(int(n[i]))
else:
even.append(int(n[i]))
i = 0
j = 0
while i < len(odd) and j < len(even):
if even[j] < odd[i]:
print(even[j], end="")
j += 1
else:
print(odd[i], end="")
i += 1
while i < len(odd):
print(odd[i], end="")
i += 1
while j < len(even):
print(even[j], end="")
j += 1
print()
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER WHILE VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.