Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = ['9',
- 'try',
- '1',
- 'it',
- '2',
- '1',
- '1',
- '=',
- '52',
- '-10'];
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- let lines = +gets();
- let sum = 0;
- let resultStr = '';
- let newLine = gets();
- if(!isNaN(newLine)){
- sum += +newLine;
- }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;
- }else if(isNaN(newLine) && isNaN(nextLine)){
- resultStr = `${resultStr}-${nextLine}`;
- }else if(!isNaN(newLine) && isNaN(nextLine)){
- console.log(sum);
- sum = 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){
- console.log(sum);
- }
- // if(resultStr === ''){
- // resultStr = 'no words';
- // console.log(resultStr);
- // console.log(sum);
- // }else{
- // console.log(resultStr.slice(1,));
- // console.log(sum);
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement