sexecutora

FirstBiggerElement

May 6th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _06.FirstBiggerElement
  7. {
  8. class FirstBiggerElement
  9. {
  10.  
  11. static int Bigger_Element_Position(int[] array)
  12. {
  13. int position = 0;
  14.  
  15. if (array[0] > array[1])
  16. {
  17. position = array[0];
  18. position = Array.IndexOf(array, position);
  19. }
  20.  
  21. else if (array[array.Length - 1] > array[array.Length - 2])
  22. {
  23. position = array[array.Length - 1];
  24. position = Array.IndexOf(array, position);
  25. }
  26.  
  27. else
  28. {
  29. for (int index = 0; index < array.Length; index++)
  30. {
  31. try
  32. {
  33. if (array[index] > array[index - 1] + array[index + 1])
  34. {
  35. position = index;
  36. break;
  37. }
  38. }
  39. catch (Exception)
  40. {
  41. }
  42.  
  43. position = -1;
  44. }
  45. }
  46. return position;
  47. }
  48.  
  49. static void Main(string[] args)
  50. {
  51. int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  52.  
  53. Bigger_Element_Position(n);
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment