Advertisement
Alexander_B

Left and Right Sum

Feb 16th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 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 DomashnoLeftAndRightSum
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. int leftSum = 0;
  16.  
  17. int rightSum = 0;
  18.  
  19. for(int i = 0; i < n; i++)
  20. {
  21. int input = int.Parse(Console.ReadLine());
  22.  
  23. leftSum += input;
  24. }
  25.  
  26. for (int i = 0; i < n; i++)
  27. {
  28. int input = int.Parse(Console.ReadLine());
  29.  
  30. rightSum += input;
  31. }
  32.  
  33. if (leftSum == rightSum)
  34. {
  35.  
  36. Console.WriteLine($"Yes, sum = {leftSum}");
  37. }
  38. else
  39. {
  40. int difference = leftSum - rightSum;
  41.  
  42. Console.WriteLine($"No, diff = {Math.Abs(difference)}");
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement