Some notes on solving problems - MarisaOJ: Marisa Online Judge
Some Notes on Solving Problems
Prism Syntax Highlighting Example
**Marisa Online Judge Overview:**
Marisa Online Judge is this automatic thingy that checks if your programming solutions are right or not in just a few seconds. Once you hit submit, your solution goes to a judge machine, kind of like when you put stuff into your program and check if it spits out the right answer. But 'cause it's a machine doing the judging, there are some quirks.
**Example Problem: [A+B](https://marisaoj.com/problem/2)**
Take this problem [A+B](https://marisaoj.com/problem/2), for example. It's asking you to read two numbers, A and B, and print their sum. Sounds easy, huh?
But if your code looks something like this in C++ or Python:
```cpp
#include <iostream>
using namespace std;
int main() {
int a, b;
cout << "Enter the value of a: ";
cin >> a;
cout << "Enter the value of b: ";
cin >> b;
cout << "The sum of " << a << " and " << b << " is: " << a + b << endl;
return 0;
}
```
or
```python
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
print(f"The sum of {a} and {b} is: {a + b}")
```
Well, sorry, but that's a no-go!
**Judge Machine Quirks:**
The reason is, even though these are technically right, the judge machine doesn't get why you're asking for input twice and explaining the sum. It's a machine, you know? All it cares about is comparing the output of your program, which comes from `cout` in C++ or `print` and `input` in Python, to what it expects.
For example, if the judge feeds your program $1$ and $2$, it expects your output to be $3$, just that single number. But with those prompts from cout and input, it thinks that's your program's output, and your solution is marked as wrong.
**Correct solution:**
The correct C++ solution is more like this:
```cpp
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
```
And for Python:
```python
a, b = map(int, input().split())
print(a + b)
```
See that line a, b = map(int, input().split())? It might look weird, but it's because the input format for the problem is "A single line contains two integers A, B," meaning A and B are on the same line. So, if you (or the judge machine) type both $4$ and $5$ on the same line like this:
```
4 5
```
The code will do its thing just fine. This can't be achieved by using two input commands.
And if you want to deal with more values on the same line, you can do this:
```python
a, b, c = map(int, input().split())
```
Now, if you're into making a list with values from the same line:
```python
A = [int(num) for num in input().split()]
```
Just a heads up, always check the Input part for each problem on MarisaOJ. It tells you how the input should be, like whether values are on the same line or not. Keep it chill, and happy coding!