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

Asked

Viewed 1,560 times

0

First of all, 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 always interested me.

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

Read 4 integer 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 and D is greater than the sum of A and B and if C and D are both positive and if variable A is even write the message "Accepted values", or write "Values not accepted".

The code I run in Visual Studio and works correctly, but when I send it to the 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");
            }

    }

}
  • I did not validate the logic of the condition... but the console worked without errors for me, both in debug and in the release execution

  • So it worked for me too. I just don’t understand why the URI doesn’t accept the code

  • Ah, I may have to create an array for the input values, I thought of that now.

  • got it, you want to pass the values as argument

  • Did you solve it? @Juliocesar

1 answer

0


A simple treatment if the values are presented as arguments to the program, if not the input is done by the Console.Radline(). Another detail, it 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");
            }            
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.