Home > Net >  Spoj task Bonus: ARRAYSUB - subarraysZadanie runtime error (NZEC) {c#}
Spoj task Bonus: ARRAYSUB - subarraysZadanie runtime error (NZEC) {c#}

Time:04-06

Good morning I ran into a problem because look at the Bonus task: ARRAYSUB - subarrays task it gives me a runtime error (NZEC) although ideone is not showing any error https://ideone.com/1eiciI Thank you

using System;
using System.Linq;
 
namespace ConsoleApp17
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int n = Convert.ToInt32((Console.ReadLine()));
 
            int k;
 
            int val = 0;
 
            int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
            k = Convert.ToInt32((Console.ReadLine()));
 
            for (int i = 0; i < n - k   1; i  )
            {
                val = arr[i];
                for (int j = i; j < i   k; j  )
                {
                    if (val < arr[j])
                    {
                        val = arr[j];
                    }
                }
 
                Console.Write(val   " ");
            }
        }
    }

I try to solve task and get accpeted

CodePudding user response:

That might help u this type of error - when the program throws an exception. In this task, probably incorrectly loaded input or exceeding the range.

I propose:

 int[] arr = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  •  Tags:  
  • c#
  • Related