Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let lines = +gets();
- let sum = 0;
- let resultStr = '';
- let counter = 0;
- let newLine = gets();
- if (!isNaN(newLine)) {
- sum += +newLine;
- counter++;
- } else if (isNaN(newLine)) {
- resultStr = `${resultStr}-${newLine}`;
- }
- for (let i = 0; i < lines - 1; i++) {
- let nextLine = gets();
- if (nextLine === '') {
- continue;
- }
- if (!isNaN(newLine) && !isNaN(nextLine)) {
- sum += +nextLine;
- counter++;
- } else if (isNaN(newLine) && isNaN(nextLine)) {
- resultStr = `${resultStr}-${nextLine}`;
- } else if (!isNaN(newLine) && isNaN(nextLine)) {
- console.log(sum);
- sum = 0;
- counter = 0;
- resultStr = `${resultStr}-${nextLine}`
- } else if (isNaN(newLine) && !isNaN(nextLine)) {
- if (resultStr[0] === '-') {
- console.log(resultStr.slice(1,));
- } else {
- console.log(resultStr);
- }
- resultStr = '';
- sum += +nextLine;
- }
- newLine = nextLine
- }
- if (resultStr[0] === '-') {
- console.log(resultStr.slice(1,));
- } else if (resultStr.length != 0) {
- console.log(resultStr);
- }
- if (sum != 0 || counter > 0) {
- console.log(sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement