## Algorithm

Problem Name: beecrowd | 3241

# Help a PhD Candidate Out!

By Christian Jonassen Norway

Timelimit: 1

Jon Marius forgot how to add two numbers while doing research for his PhD. And now he has a long list of addition problems that he needs to solve, in addition to his computer science ones! Can you help him?

On his current list Jon Marius has two kinds of problems: addition problems on the form ”a+b” and the ever returning problem ”P=NP”. Jon Marius is a quite distracted person, so he might have so solve this last problem several times, since he keeps forgetting the solution. Also, he would like to solve these problems by himself, so you should skip these.

## Input

The first line of input will be a single integer N (1 ≤ N ≤ 1000) denoting the number of testcases. Then follow N lines with either ”P=NP” or an addition problem on the form ”a + b”, where a, b ∈ [0, 1000] are integers.

## Output

Output the result of each addition. For lines containing “P=NP”, output “skipped”.

 Input Sample Output Sample 4 2+2 1+2 P=NP 0+0 4 3 skipped 0

## Code Examples

### #1 Code Example with Javascript Programming

```Code - Javascript Programming```

``````
const { readFileSync } = require("node:fs")
const [numLines, ...input] = readFileSync("/dev/stdin", "utf8").split("\n", 1000 + 1)

function evaluateSimpleLinearExpression(expression = "") {
while (expression.includes("("))
expression = expression
.replace(/\(([\d+\-*/ ]+?)\)/g, (_, op) => String(evaluateSimpleLinearExpression(op)))

expression = expression
.replace(/(-?\d+)\s*?([*/])\s?(-?\d+)/g, (_, numA, operator, numB) => {
if (operator === "*") return String(Number.parseInt(numA, 10) * Number.parseInt(numB, 10))
if (operator === "/") return String(Number.parseInt(numA, 10) / Number.parseInt(numB, 10))
})
.replace(/(-?\d+)\s*?([+-])\s*?(-?\d+)/g, (_, numA, operator, numB) => {
if (operator === "+") return String(Number.parseInt(numA, 10) + Number.parseInt(numB, 10))
if (operator === "-") return String(Number.parseInt(numA, 10) - Number.parseInt(numB, 10))
})

return Number(expression)
}

function main() {
const output = new Array(Number.parseInt(numLines, 10))

for (let index = 0; index  <  output.length; index++) {
const line = input[index]
output[index] = (line === "P=NP") ? "skipped" : evaluateSimpleLinearExpression(line)
}

console.log(output.join("\n"))
}

main()

``````
Copy The Code &

Input

cmd
4 2+2 1+2 P=NP 0+0

Output

cmd
4 3 skipped 0

### #2 Code Example with Javascript Programming

```Code - Javascript Programming```

``````
var lines = input.split('\n');
var prompt = function(texto){ return lines.shift(); };
let count = parseInt(prompt("quantidade e vezes")); x = 0, y = 0;

for(count; count > 0; count--) {

let soma = prompt("soma");
if (soma != 'P=NP') {
soma = soma.split('+');
x = parseInt(soma.shift());
y = parseInt(soma.shift());

soma = x + y;
console.log(soma);
} else {
console.log('skipped');
}
soma = 0;
}
``````
Copy The Code &

Input

cmd
4 2+2 1+2 P=NP 0+0

Output

cmd
4 3 skipped 0