Skip to content

Instantly share code, notes, and snippets.

@grhkm21

grhkm21/q0.md Secret

Created February 16, 2024 16:38
How to solve Problem 0?

Test question

This problem will not count towards your final score.

PROBLEM STATEMENT

You are given a thousand pairs of integers a and b . Output the sum of each pair.

INPUT

There are 1000 sets of inputs.

Each set of inputs contains 2 lines.

  • The first line is the integer a . The second line is the integer b .

OUTPUT

1000 lines, where each line is the output a + b of the corresponding set of inputs.

CONSTRAINTS

10 18 a , b 10 18

BONUS

Since grhkm is feeling nice today, here is a solution written in Python:

# Iterate 1000 times
for _ in range(1000):
    # Read the input
    a = int(input())
    b = int(input())
    # Output the answer
    print(a + b)

To run this on your machine, type python3 q0.py < 1.in > 1.out. Replace q0.py with your file name, 1.in and 1.out with the correct input and output files.

Here is the solution code in C++:

#include <iostream>

int main() {
  long a, b;
  for (long T = 1; T <= 1000; T++) {
    std::cin >> a >> b;
    std::cout << a + b << std::endl;
  }
}

To run this on your machine, type g++ q0.cpp -Wall -o q0 && ./q0 < 1.in > 1.out. Replace q0.cpp with your file name, 1.in and 1.out with the correct input and output files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment