Codeforces 1807A Plus or Minus Solution & Explanation

Difficulty : 800

Problem Description

You are given three integers a, b, and c such that exactly one of these two equations is true:

  • a+b=c
  • a−b=c

Output + if the first equation is true, and – otherwise.

Input

The first line contains a single integer t (1≤t≤162) — the number of test cases.

The description of each test case consists of three integers a, b, c (1≤a,b≤9, −8≤c≤18). The additional constraint on the input: it will be generated so that exactly one of the two equations will be true.

Output

For each test case, output either + or – on a new line, representing the correct equation.

Examples

Input11
1 2 3
3 2 1
2 9 -7
3 4 7
1 1 2
1 1 0
3 3 6
9 9 18
9 9 0
1 9 -8
1 9 10
Output+

+
+
+
+

+

Note

In the first test case, 1+2=3.

In the second test case, 3−2=1.

In the third test case, 2−9=−7. Note that c can be negative.


Solution

We can use a for loop and a simple equality statement to check the answer.

C# Solution

Solution1

int t = int.Parse(Console.ReadLine());

for(int i=0; i<t; i++){
    int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    if(arr[0]+arr[1]==arr[2]){
        Console.WriteLine("+");
    }   
    else{
        Console.WriteLine("-");   
    }
}
Klook.com

Conclusion

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 1807A – Codeforces

Some Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *