Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace EqualPairs
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine()); // number of pairs
- bool equalValue = true; // holds a value if all pairs are equal
- int num = 0; // hold input number value
- int sum = 0; // hold sum of pair of numbers
- int lastSum = 0; // hold last pair sum
- int maxDiff = 0; // hold maximum difference between pairs
- for (int i = 1; i <= n; i++) // iterate to n value for each pair
- {
- lastSum = sum; // last sum value
- sum = 0; // sum becomes 0 for next iterration
- for (int x = 0; x <= 1; x++)
- {
- num = int.Parse(Console.ReadLine()); // input number
- sum += num; // sum equals itself + input number
- }
- //if last sum is different than 0 then we get maximum difierence between last sum and current sum as abs value
- if (lastSum != 0)
- {
- maxDiff = Math.Abs(lastSum - sum); // get the max difference
- if (maxDiff == 0) // if maximum difference is 0 the pairs are equal
- {
- equalValue = true;
- }
- else
- {
- equalValue = false;
- }
- }
- }
- if (equalValue)
- {
- Console.WriteLine($"Yes, value={sum}");
- }
- else
- {
- Console.WriteLine($"No, maxdiff={maxDiff}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement