Runtime error - 1035 - Selection Test 1 - URI Online Judge



  • First, I don't have much experience with C#, I just know programming logic. I'm studying C# out of curiosity, it's a language that's always interested me.

    I am studying for the URI and I am not able to solve this exercise:

    Read 4 whole values A, B, C and D. Next, if B is greater than C and if D is greater than A, and the sum of C with D is greater than the sum of A and B and if C and D, both are positive and if the variable A for par write the message "Accessed values", otherwise write "Valores nãoo accepted."

    The code I run in Visual Studio and works correctly, but when sending pro URI it gives the error:

    Runtime error

    The code is like this:

    using System; 
    

    class URI {

    static void Main(string[] args) { 
    
            int a, b, c, d;
    
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            d = int.Parse(Console.ReadLine());
    
            if ( (b > c) &&  (d > a) && ((c + d) > (a + b)) && (c > 0 && d > 0) && (a % 2 == 0)) {                
                Console.WriteLine("Valores aceitos");
            } else {
                Console.WriteLine("Valores nao aceitos");
            }
    
    }
    

    }



  • A simple treatment if the values are presented as arguments for the program, if not the input is done by the Console. Radline(). Another detail is not good you do not indicate a namespace for your application.

    using System;
    

    namespace ConsoleApp
    {
    class URI
    {
    static void Main(string[] args)
    {
    int a, b, c, d;
    if (args.Length == 4)
    {
    a = int.Parse(args[0]);
    b = int.Parse(args[1]);
    c = int.Parse(args[2]);
    d = int.Parse(args[3]);
    }
    else
    {
    a = int.Parse(Console.ReadLine());
    b = int.Parse(Console.ReadLine());
    c = int.Parse(Console.ReadLine());
    d = int.Parse(Console.ReadLine());
    }

            if ((b > c) && (d > a) && ((c + d) > (a + b)) && (c > 0 && d > 0) && (a % 2 == 0))
            {
                Console.WriteLine("Valores aceitos");
            }
            else
            {
                Console.WriteLine("Valores nao aceitos");
            }            
        }
    }
    

    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 3
  • 2
  • 2
  • 2
  • 2
  • 2
  • 3
  • 2
  • 2
  • 2
  • 2