Advertisement
Milislavskii

Increasing Absolute Differences

Mar 14th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. namespace Problem2
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     class IncreasingAbsoluteDifferences
  7.     {
  8.         static void Main()
  9.         {
  10.             int t = int.Parse(Console.ReadLine());
  11.             for (int i = 0; i < t; i++)
  12.             {
  13.                 string[] line = Console.ReadLine().Split(' ');
  14.                 long[] numbers = new long[line.Length];
  15.  
  16.                 for (int j = 0; j < numbers.Length; j++)
  17.                 {
  18.                     numbers[j] = long.Parse(line[j]);
  19.                 }
  20.  
  21.                 long[] differencesArray = new long[numbers.Length - 1];
  22.  
  23.                 for (int k = 1; k < numbers.Length; k++)
  24.                 {
  25.                     long absDifference = Math.Abs(numbers[k - 1] - numbers[k]);
  26.                     differencesArray[k - 1] = absDifference;
  27.                 }
  28.                 string result = "";
  29.                 for (int x = 0; x < differencesArray.Length-1; x++)
  30.                 {
  31.                     if (differencesArray[x] > differencesArray[x + 1])
  32.                     {
  33.                         result = "False";
  34.                         break;
  35.                     }
  36.                     else
  37.                     {
  38.                         if (Math.Abs(differencesArray[x] - differencesArray[x+1]) > 1)
  39.                         {
  40.                             result = "False";
  41.                             break;
  42.                         }
  43.                         else
  44.                         {
  45.                             result = "True";
  46.                         }  
  47.                     }
  48.                    
  49.                 }
  50.                 Console.WriteLine(result);
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement