Advertisement
Guest User

Untitled

a guest
Feb 18th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Task6
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             bool check = true;
  10.             bool test = false;
  11.             int n = Convert.ToInt32(Console.ReadLine());
  12.             int k = Convert.ToInt32(Console.ReadLine());
  13.             string str = Console.ReadLine();
  14.  
  15.             if (str.Contains("?"))
  16.                 test = true;
  17.  
  18.             string minstr = str.Replace("?", "1");
  19.             string maxstr = str.Replace("?", "9");
  20.  
  21.             int num = Convert.ToInt32(k * (Math.Floor(Convert.ToInt32(minstr) * 1.0 / k)));
  22.             char[] numMas;
  23.  
  24.             for (; ; )
  25.             {
  26.                 if (test && (num > Convert.ToInt32(maxstr)))
  27.                 {
  28.                     Console.WriteLine(-1);
  29.                     break;
  30.                 }
  31.  
  32.                 numMas = num.ToString().ToCharArray();
  33.  
  34.                 for (int i = 0; i < str.Length; i++)
  35.                 {
  36.                     if (numMas[i] == '0')
  37.                     {
  38.                         check = false;
  39.                         break;
  40.                     }
  41.  
  42.                     if ((str[i] != '?') && (str[i] != numMas[i]))
  43.                     {
  44.                         check = false;
  45.                         break;
  46.                     }
  47.                 }
  48.  
  49.                 if ((str.Length == numMas.Length) && check)
  50.                 {
  51.                     Console.WriteLine(num);
  52.                     break;
  53.                 }
  54.  
  55.                 if (num > Convert.ToInt32(maxstr))
  56.                 {
  57.                     Console.WriteLine(-1);
  58.                     break;
  59.                 }
  60.  
  61.                 check = true;
  62.                 num += k;
  63.             }
  64.             Console.ReadLine();
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement