-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1954C.cpp
More file actions
50 lines (42 loc) · 1.1 KB
/
1954C.cpp
File metadata and controls
50 lines (42 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#define MAXN 2000000000
#define llu unsigned long long
#include <bits/stdc++.h>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string x, y;
cin >> x >> y;
int n = x.size();
// once you have a larger LSB, the other bit should be the smallest!
// suppose that I want x is larger than y.
bool same = false;
for (int i = 0; i < n; ++i) {
// 4 cases:
// 1., 2. same in history(same == false)
// if x > y -> do nothing
// if x < y -> swap
// 3., 4. in history not the same but x > y (same == true)
// if x > y -> swap
// if x < y -> do nothing
if (same == (x[i] > y[i]))
swap(x[i], y[i]);
same |= (x[i] != y[i]);
}
cout << x << endl;
cout << y << endl;
}
return 0;
}