Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Task6
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool check = true;
- bool test = false;
- int n = Convert.ToInt32(Console.ReadLine());
- int k = Convert.ToInt32(Console.ReadLine());
- string str = Console.ReadLine();
- if (str.Contains("?"))
- test = true;
- string minstr = str.Replace("?", "1");
- string maxstr = str.Replace("?", "9");
- int num = Convert.ToInt32(k * (Math.Floor(Convert.ToInt32(minstr) * 1.0 / k)));
- char[] numMas;
- for (; ; )
- {
- if (test && (num > Convert.ToInt32(maxstr)))
- {
- Console.WriteLine(-1);
- break;
- }
- numMas = num.ToString().ToCharArray();
- for (int i = 0; i < str.Length; i++)
- {
- if (numMas[i] == '0')
- {
- check = false;
- break;
- }
- if ((str[i] != '?') && (str[i] != numMas[i]))
- {
- check = false;
- break;
- }
- }
- if ((str.Length == numMas.Length) && check)
- {
- Console.WriteLine(num);
- break;
- }
- if (num > Convert.ToInt32(maxstr))
- {
- Console.WriteLine(-1);
- break;
- }
- check = true;
- num += k;
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement