Mohan is very particular about numbers. There are ‘K’ digits that he dislikes: D1, D2,…Dk. Mohan is shopping, and now paying at the cashier. His total is ‘N’ yen (the currency of Japan), thus he has to hand at least ‘N’ yen to the cashier (and possibly receive the change).
However, as mentioned before, he is very particular about numbers. When he hands money to the cashier, the decimal notation of the amount must not contain any digits that he dislikes. Under this condition, he will hand the minimum amount of money.
Input:
The input is given from Standard Input in the following format:
N K
D1 D2...Dk
Output:
Print the output the amount of money that mohan will hand to the cashier.
#include<stdio.h> #include<stdlib.h> #include<stdbool.h> int N, K, x, re,i; int b[10]; bool check(int x); int main(){ scanf("%d %d", &N, &K); int *D = (int *)malloc(sizeof(int)*K); for( i = 1; i <= K; i++){ scanf("%d", D); b[*D]++; } for( i = N;;i++){ if(check(i)){ re = i; break; } } printf("%d",re); return 0; } bool check(int x){ while(x){ if(b[x%10])return 0; x/=10; } return true; }
INPUT_1:
1021 8
1 2 3 4 5 6 7 8
OUTPUT:
9000
INPUT_2:
1001 7
4 3 5 7 2 8 3
OUTPUT:
1001
INPUT_3:
2500 5
1 2 3 4 5
OUTPUT:
6000
INPUT_4:
5570 6
2 1 5 4 3 6
OUTPUT:
7000
ILLUSTRATION
Morae Q!
- Find how long will it take till the next fortune year from the current year.
- Find if it’s possible to distribute all the crayons into boxes and satisfy all the conditions.
- Compute sum of numbers using call by reference.
- Compute the amount of money to be handed over with conditions.
- Find the total number of beautiful triplets in the sequence.
- Find the total amount each worker has to pay individually.
- Find the minimum distance between any pair of equal elements in the array.
- Compute the maximum possible value of the given equation.
- Find the age of the student at the time of joining.
- Compute the total number of photos at each restaurant .
- Find the sum of digits of the number using Union datatype.
- Generate the details of the novels in the expected format.
- Sort the student details based on their names in ascending order.
- Find a way to move the king from current position to different square on chessboard.
- Find the time differences in the two different time zones.
- Identifying the greatest number with a numerator and denominator.
- Find the Minimum number of packages to supply all the bases.
- Tower of Hanoi, A puzzle.
- Compute the sum of array of elements using recursion method.
- Find the super digit of an integer using the rules.