Advertisement
Alexander_B

Equal Pairs

Feb 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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 DomashnoEqualPairs
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. int numberOfInputs = n * 2;
  16.  
  17. int coupleSum1 = 0;
  18.  
  19. int coupleSum2 = 0;
  20.  
  21. int lastDifference = 0;
  22.  
  23. int maxDifference = 0;
  24.  
  25.  
  26. for (int i = 1; i <= n; i++)
  27. {
  28. int input = int.Parse(Console.ReadLine());
  29. int input2 = int.Parse(Console.ReadLine());
  30.  
  31. if (i % 2 == 1 && n != 1)
  32. {
  33. coupleSum1 = input + input2;
  34. }
  35. else if(i % 2 == 0 && n != 1)
  36. {
  37. coupleSum2 = input + input2;
  38. }
  39. else
  40. {
  41. coupleSum1 = input + input2;
  42. coupleSum2 = 0;
  43. }
  44.  
  45. int difference = Math.Abs(coupleSum1 - coupleSum2);
  46. if (difference > maxDifference&&i>1)
  47. {
  48. maxDifference = difference;
  49. lastDifference = difference;
  50. }
  51.  
  52.  
  53. }
  54.  
  55. if (maxDifference == 0)
  56. {
  57. Console.WriteLine($"Yes, value={coupleSum1}");
  58. }
  59. else
  60. {
  61. Console.WriteLine($"No, maxdiff={lastDifference}");
  62. }
  63.  
  64.  
  65.  
  66.  
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement