Advertisement
plamen27

Last Task -- Equal Pairs

Jun 23rd, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 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 _12_Equal_Pairs
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var n = int.Parse(Console.ReadLine());
  14. var sum = 0;
  15. var sumPrev = 0;
  16. var diff = 0;
  17. var diffMax = 0;
  18.  
  19. for (var i = 1; i <= n; i++)
  20. {
  21. sumPrev = sum;
  22. var numOne = int.Parse(Console.ReadLine());
  23. var numTwo = int.Parse(Console.ReadLine());
  24. sum = numOne + numTwo;
  25.  
  26. }
  27. for (var j = 2; j <= n; j++)
  28. {
  29. diff = Math.Abs(sum - sumPrev);
  30. if (diff > diffMax)
  31. {
  32. diffMax = diffMax + diff;
  33. }
  34. }
  35.  
  36. if (diffMax == 0)
  37. {
  38. Console.WriteLine("Yes, value ={0}", sum);
  39. }
  40. else
  41. {
  42. Console.WriteLine("No, maxdiff ={0}", diffMax);
  43. }
  44.  
  45.  
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement