Video:
Read problem statements in Bengali, Mandarin Chinese, Russian, and Vietnamese as well.
You are given an integer and a digit . Find the minimum non-negetive integer you should add to such that the final value of does not contain the digit .
Input Format
- The first line contains denoting the number of test cases. Then the test cases follow.
- Each test case contains two integers and on a single line denoting the original number and the digit you need to avoid.
Output Format
For each test case, output on a single line the minimum non-negetive integer you should add to .
Constraints
Subtasks
- Subtask 1 (100 points): Original constraints
Sample Input 1
5
21 5
8 8
100 0
5925 9
434356 3
Sample Output 1
0
1
11
75
5644
Explanation
Test case : does not contain the digit . Hence there is no need to add any integers to .
Test case : If is added to , it becomes equal to , which does not contain the digit .
Test case : The minimum integer you should add to such that the final value of does not contain the digit is .
Test case : The minimum integer which is greater than and does not contain the digit is . So we should add .
Digit Removal Solution:
#include<bits/stdc++.h>
using namespace std;
int isMin(int n, int d){
int newN = n, rem , count =0, c = 0;
while(newN>0){
rem = newN % 10;
newN = newN /10;
c++;
if(rem == d){
newN = newN*pow(10,c)+(rem+1)*pow(10,c-1);
count = newN -n;
c = 0;
}
}
return count;
}
int main()
{
int t;
cin>>t;
while(t--){
int n, d;
cin>>n>>d;
cout<<isMin(n, d) <<endl;
}
return 0;
}
0 Comments