** Solution to Problem 1807A – Plus or Minus**
Hello Codeforces!
Today I am sharing my solution and explanation for Problem 1807A – Plus or Minus. This is a very beginner-friendly problem but a good warm-up to understand simple conditions in programming.
Problem Statement
You are given three integers a, b, and c.
You need to determine whether:
a + b = c → then print "+"
a — b = c → then print "-"
It is guaranteed in the test cases that one of these will always be true.
Approach
The logic is very simple:
Read the number of test cases t.
For each test case, take three integers a, b, c.
Check:
If a + b == c → print "+"
Else if a — b == c → print "-"
Since the problem guarantees that one of them will always hold true, we don’t need to worry about any other condition.
Code (Java) import java.util.Scanner;
public class problem1807A { public static void main(String [] args){ Scanner sc = new Scanner(System.in); int t = sc.nextInt(); // number of test cases
while(t-- > 0){
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a + b == c)
System.out.println("+");
else if (a - b == c)
System.out.println("-");
}
sc.close();
}}
Example Dry Run Input: 3 1 2 3 3 1 2 2 3 1
Step-by-step:
For 1 2 3: 1 + 2 = 3 → Output "+"
For 3 1 2: 3 — 1 = 2 → Output "-"
For 2 3 1: 2 — 3 = -1 (not equal) 2 + 3 = 5 (not equal either) But since problem guarantees one case will be true → actual test data won’t have this situation.
Output: + - **** Complexity
Time Complexity: O(t) (since we check each test case once)
Space Complexity: O(1) (no extra storage needed)
Conclusion
This problem was a simple conditional check. It helps beginners practice reading input, applying if-else conditions, and producing correct output format.
That’s all! Happy coding and keep solving!







