Advertisement
Guest User

Untitled

a guest
May 7th, 2015
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace FirstLarger_4
  8. {
  9.     class FirstLarger_4
  10.     {
  11.         static int[] arr;
  12.  
  13.         static bool GetFirstLarger(int idx)
  14.         {
  15.             bool firstLarger;
  16.             if (idx == 0)
  17.             {
  18.                 firstLarger = arr[idx] > arr[idx + 1];
  19.             }
  20.             else if (idx == arr.Length - 1)
  21.             {
  22.                 firstLarger = arr[idx] > arr[idx - 1];
  23.             }
  24.             else
  25.             {
  26.                 firstLarger = arr[idx] > arr[idx - 1] && arr[idx] > arr[idx + 1];
  27.             }
  28.             return firstLarger;
  29.         }
  30.         static void Main(string[] args)
  31.         {
  32.             string inputArray = Console.ReadLine();
  33.             arr = inputArray.Split().Select(int.Parse).ToArray();
  34.             bool isGreater = false;
  35.  
  36.             for (int i = 0; i < arr.Length; i++)
  37.             {
  38.                 if (GetFirstLarger(i))
  39.                 {
  40.                     Console.WriteLine("First Larger element is {0}",i);
  41.                     isGreater = true;
  42.                     break;
  43.                 }            
  44.             }
  45.             if (!isGreater)
  46.             {
  47.                 Console.WriteLine("-1");
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement