Advertisement
Kolimnared

Pairs

Oct 17th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. class Pairs
  4. {
  5. static void Main(string[] args)
  6. {
  7. string str = Console.ReadLine();
  8. int[] numsSep = Array.ConvertAll(str.Split(' '), int.Parse);
  9. int length = numsSep.Length;
  10. int[] nums = new int[(length/2)];
  11.  
  12. for (int i = 0; i < numsSep.Length; i++)
  13. {
  14. nums[(i / 2)] += numsSep[i];
  15. }
  16.  
  17. int firstValue = nums[0];
  18. bool areEquals = true;
  19.  
  20. foreach (var item in nums) {
  21. if (firstValue != item) {
  22. areEquals = false;
  23. }
  24. }
  25.  
  26. if (areEquals){
  27. Console.WriteLine("Yes, value={0}", firstValue);
  28. }
  29. else {
  30. int maxDiff = int.MinValue;
  31. for (int i = 0; i < ((length/2) - 1); i++) {
  32. if (Math.Abs(nums[i] - nums[i + 1]) > maxDiff) {
  33. maxDiff = Math.Abs(nums[i] - nums[i + 1]);
  34. }
  35. }
  36. Console.WriteLine("No, maxdiff={0}", maxDiff);
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement