Skip to content

Commit c810585

Browse files
authored
Add files via upload
1 parent 1e1b73e commit c810585

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

Array.cpp/DIGITREM.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
int mod=1e9+7;
5+
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
6+
typedef long long int ll;
7+
8+
int main() {
9+
fast;
10+
int t;
11+
cin>>t;
12+
while(t--){
13+
14+
15+
ll n,d;
16+
17+
cin>>n>>d;
18+
string s= to_string(n);
19+
ll len = s.length();
20+
21+
if(d==0){
22+
int a= len;
23+
for(int i = 0; i<len;i++){
24+
if(s[i]=='0'){
25+
s[i]='1';
26+
a=i;
27+
break;
28+
}
29+
}
30+
for(int j=a+1;j<len;j++){
31+
s[j]='1';
32+
}
33+
}
34+
else if(d==9){
35+
if(s[0]=='9'){
36+
for(int i=0;i<len;i++){
37+
s[i]='0';
38+
}
39+
s="1"+s;
40+
}
41+
else{
42+
int b=len;
43+
for(int i=0;i<len;i++){
44+
if(s[i]=='9'){
45+
for(int j=i-1;j>=0;j--){
46+
if(s[j]<='7'){
47+
s[j]++;
48+
b=j;
49+
goto cvv;
50+
}
51+
}
52+
for(int i=0;i<len;i++){
53+
s[i]='0';
54+
}
55+
s="1"+s;
56+
goto fvv;
57+
}
58+
}
59+
cvv:;
60+
for(int j = b+1;j<len;j++){
61+
s[j]='0';
62+
}
63+
fvv:;
64+
}
65+
}
66+
else{
67+
int i=0;
68+
for(i=0;i<len;i++){
69+
if((s[i]-48)==d){
70+
s[i]=s[i]+1;
71+
break;
72+
}
73+
}
74+
for(int j=i+1; j<len ; j++){
75+
s[j]='0';
76+
}
77+
}
78+
ll ans = stoll(s);
79+
cout << ans-n << endl;
80+
}
81+
return 0;
82+
}
83+
84+
85+
86+
87+
88+

0 commit comments

Comments
 (0)