Algorithm
Problem Name: 2 AD-HOC - beecrowd | 1387
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1387
Og
Timelimit: 1
Og is a caveman with many children, and he wants to count them all. Og counts his sons with his left hand and his daughters with his right hand.
However, Og is very dumb, and can't add the two counts, so he asked you to write him a program that will do the addition.
Input
The input contains several test cases. Each test case consists of a single line containing two integers L and R, separated by a single space, indicating respectively the number of sons and daughters (1 ≤ L, R ≤ 5).
The end of input is indicated by L = R = 0.
Output
For each test case in the input print a line containing a single integer indicating how many children Og has.
Sample Input | Sample Output |
2 2 |
4 |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main (void)
{
unsigned char dir, esq;
while (1)
{
scanf("%hhd %hhd", &dir, &esq);
if (esq == 0 && dir == 0)
break;
printf("%hhd\n", esq+dir);
}
}
Copy The Code &
Try With Live Editor
Input
2 3
5 5
1 1
0 0
Output
5
10
2
#2 Code Example with C++ Programming
Code -
C++ Programming
#include <iostream>
using namespace std;
int main(void) {
int a, b;
while (cin >> a >> b) {
if (a == 0 && b == 0) break;
cout << a + b << endl;
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
2 3
5 5
1 1
0 0
Output
5
10
2
#3 Code Example with Java Programming
Code -
Java Programming
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
String l;
String[] P;
while (!(l = read()).equals("0 0")) {
P = l.split("\\s");
out.println(toInt(P[0]) + toInt(P[1]));
}
out.close();
}
private static String read() throws IOException {
return in.readLine();
}
private static int toInt(String s) {
return Integer.parseInt(s);
}
}
Copy The Code &
Try With Live Editor
Input
2 3
5 5
1 1
0 0
Output
5
10
2
#4 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const input = readFileSync("/dev/stdin", "utf8")
.split("\n")
.map(line => line.split(" ").map(value => Number.parseInt(value, 10)))
function main() {
const responses = []
for (const [A, B] of input)
if (A == 0 || B == 0) break
else responses.push(A + B)
console.log(responses.join("\n"))
}
main()
Copy The Code &
Try With Live Editor
Input
2 3
5 5
1 1
0 0
Output
5
10
2
#5 Code Example with Python Programming
Code -
Python Programming
while True:
a, b = [int(x) for x in input().split()]
if a == b == 0: break
print(a+b)
Copy The Code &
Try With Live Editor
Input
2 3
5 5
1 1
0 0
Output
5
10
2