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

0

Firstly, I do not have much experience with C #, I just know programming logic. I'm studying C # out of curiosity, it's a language that has always interested me.

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

  

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

The code I run in Visual Studio works fine, but when I send it to the URI it gives the error:

  

Runtime error

The code looks 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");
            }

    }

}
    
asked by anonymous 12.12.2017 / 16:20

1 answer

0

A simple treatment if the values are presented as arguments to the program, otherwise the input is done by 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");
            }            
        }
    }
}
    
12.12.2017 / 19:04