Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _06.FirstBiggerElement
- {
- class FirstBiggerElement
- {
- static int Bigger_Element_Position(int[] array)
- {
- int position = 0;
- if (array[0] > array[1])
- {
- position = array[0];
- position = Array.IndexOf(array, position);
- }
- else if (array[array.Length - 1] > array[array.Length - 2])
- {
- position = array[array.Length - 1];
- position = Array.IndexOf(array, position);
- }
- else
- {
- for (int index = 0; index < array.Length; index++)
- {
- try
- {
- if (array[index] > array[index - 1] + array[index + 1])
- {
- position = index;
- break;
- }
- }
- catch (Exception)
- {
- }
- position = -1;
- }
- }
- return position;
- }
- static void Main(string[] args)
- {
- int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- Bigger_Element_Position(n);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment