Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. //take input from console
  8. string first = Console.ReadLine();
  9. string[] splitted = first.Split(' ');//split them with empty spaces
  10.  
  11. int[] Arr = new int[splitted.Length];//int array for string console values
  12. for (int i = 0; i < splitted.Length; i++)//goes true all elements and converts them into Int32
  13. {
  14. Arr[i] = int.Parse(splitted[i]);
  15. }
  16. //for (int i = 0; i < Arr.Length; i++)//print array to see what happened
  17. //{
  18. // Console.WriteLine(Arr[i]);
  19. //}
  20.  
  21. int[] novArr = new int[(Arr.Length / 2)];
  22.  
  23. int sum = 0;
  24.  
  25. for (int i = 0; i < Arr.Length; i += 2)
  26. {
  27. if (i + 1 < Arr.Length)
  28. {
  29. novArr[sum] = Arr[i] + Arr[i + 1];
  30. }
  31. else
  32. {
  33. novArr[sum] = Arr[i];
  34. }
  35. sum++;
  36. }
  37.  
  38. //check if the values are equal
  39. int counter = 0;
  40. int value = 0;
  41. for (int i = 0; i < novArr.Length - 1; i++)
  42. {
  43. if (novArr[i] == novArr[i + 1])
  44. {
  45. counter++;
  46. }
  47. else
  48. {
  49. //#1 EDIT: looking for the MAX difference,
  50. //Math.Abs should be here as well
  51. //example: Math.Max(90,-150) = 90...
  52.  
  53. value = Math.Max(value, Math.Abs(novArr[i] - novArr[i + 1]));
  54. }
  55. }
  56.  
  57. //#2 EDIT: formatting edit + no Math.Abs here
  58. if (counter == novArr.Length - 1)
  59. {
  60. Console.WriteLine("Yes, value={0}", novArr[0]);
  61. }
  62. else
  63. {
  64. Console.WriteLine("No, maxdiff={0}", value);
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement