TOPIC

Runtime Error - C#

    asked 4 months ago

Por algum motivo no URI ele me dá esse erro, mas quando testo no compilador na minha máquina, ou mesmo no compilador online, todos os casos de teste no uDebug funcionam como deveriam.


using System;
using System.Linq;

class Program
{
  static void Main(string[] args)
  {
    var input = Console.ReadLine().Split(' ');
    var hidden = input[0];
    var mult = input[1];

    if (hidden[0] == '?')
      hidden = hidden.Remove(0, 1).Insert(0, "1");

    if (mult[mult.Length - 1] == '2' && hidden[hidden.Length - 1] != '?' && int.Parse(hidden[hidden.Length - 1].ToString()) % 2 != 0)
      Console.WriteLine('*');
    else
      Verify(hidden, mult);
  }

  static void Verify(string num, string mult, int index = 0)
  {
    if (index == num.Length)
    {
      if (IsMultiple(num, mult))
      {
        Console.WriteLine(num);
        Environment.Exit(1);
      }
    }
    else if (num[index] != '?')
      Verify(num, mult, index + 1);
    else
      foreach (var digit in Enumerable.Range(0, 10))
        Verify(num.Remove(index, 1).Insert(index, digit.ToString()), mult, index + 1);
  }

  static bool IsMultiple(string num, string mult)
  {
    if (num.Length <= mult.Length)
      return int.Parse(num) % int.Parse(mult) == 0;

    var tested = num.Substring(0, mult.Length + 1);
    var result = int.Parse(tested) % int.Parse(mult);

    num = result.ToString() + num.Remove(0, mult.Length + 1);
    return IsMultiple(num, mult);
  }
}

Remember not post solutions. Your post may be reviewed by our moderators.