ZeroJudge A244: Training ~ for + if

Content: 

Hope the people who are learning about for loops and just starting coding will keep up the good work! 

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The first line contains a positive integer N, indicating that the following N lines each contain three positive integers a, b, and c (1 ≤ b, c ≤ 2147483647, 1 ≤ a ≤ 4).If a=1, please output b+c.
If a=2, please output b-c.
If a=3, please output b*c.
If a=4, please output b/c.
The results should be output as an integer.
4
1 2 3
2 2 3
3 2 3
4 2 3
5
-1
6
0

Thought Process

In this problem, you need to use "long long int" to avoid exceeding the range of int. Use if statements to determine which operation (addition, subtraction, multiplication, or division) to perform for the output.

Sample Code-ZeroJudge A244: Training ~ for + if

#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i<N; i++)
    {
      long long int a, b, c;
      cin >> a >> b >> c;
      if (a == 1) cout << b+c << endl;
      else if (a == 2) cout << b-c << endl;
      else if (a == 3) cout << b*c << endl;
      else if (a == 4) cout << b/c << endl;
    }
}

//ZeroJudge A244
//Dr. SeanXD

Comments