forked from saurav2127/hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdigitremoval.cpp
More file actions
50 lines (43 loc) · 854 Bytes
/
digitremoval.cpp
File metadata and controls
50 lines (43 loc) · 854 Bytes
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
#include <cmath>
#include <iostream>
using namespace std;
int check(int n, int d) {
int c = 0, place_vl = 0;
int temp = n, temp1 = n;
while (temp > 0) {
c++;
if (temp % 10 == d) {
place_vl = c;
}
temp /= 10;
}
if (place_vl == 0) {
return 0;
}
int newn = 0, tens = 1;
tens = int(pow(10, place_vl - 1));
newn = temp1 - (temp1 / tens) * tens;
int p = place_vl;
if (d == 0) {
tens = 0;
while (p--) {
tens = tens * 10 + 1;
}
}
int t = tens - newn;
if (d == 9 && place_vl != 0) {
return t + check(n + t, d);
} else {
return t;
}
}
int main() {
int t;
cin >> t;
while (t--) {
int n, d;
cin >> n >> d;
cout << check(n, d)<<endl;
}
return 0;
}