-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCC-CHDIGER.cpp
More file actions
59 lines (56 loc) · 1.14 KB
/
CC-CHDIGER.cpp
File metadata and controls
59 lines (56 loc) · 1.14 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
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) int x; cin>>x; while(x--)
#define rep(x,a,n,b) for(x=a;x<=n;x+=b)
#define rept(x,a,n,b) for(x=a;x>=n;x-=b)
void shammi() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll maxDigit(ll n) {
ll mx = 0;
while (n > 0) {
mx = max(mx, n % 10);
n /= 10;
}
return mx;
}
int main() {
shammi();
w(t) {
string n;
char c;
cin >> n >> c;
int l = n.length();
if (n[l - 1] > c) n[l - 1] = c;
int i;
string ans = "";
rep(i, 1, l - 1, 1)
{
int j = i - 1;
while (j >= 0 && n[j] == '0') j--;
if (j >= 0 && n[i] < n[j])
{
n[j] = '0';
n += c;
i--;
}
}
l = n.length();
rep(i, 0, l - 1, 1)
if (n[i] != '0')
ans += n[i];
cout << ans << endl;
}
return 0;
}