Advertisement
bai_onzi

Untitled

Feb 13th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let input = ['9',
  2.     'try',
  3.     '1',
  4.     'it',
  5.     '2',
  6.     '1',
  7.     '1',
  8.     '=',
  9.     '52',
  10.     '-10'];
  11.  
  12.  
  13. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  14.  
  15. let lines = +gets();
  16. let sum = 0;
  17. let resultStr = '';
  18.  
  19.  
  20.     let newLine = gets();
  21.     if(!isNaN(newLine)){
  22.         sum += +newLine;
  23.        
  24.     }else if(isNaN(newLine)){
  25.         resultStr = `${resultStr}-${newLine}`;
  26.     }
  27.    
  28. for(let i = 0; i < lines - 1; i++){
  29.    
  30.     let nextLine = gets();
  31.     if(nextLine === ''){
  32.         continue;
  33.     }
  34.    
  35.     if(!isNaN(newLine) && !isNaN(nextLine)){
  36.         sum += +nextLine;
  37.     }else if(isNaN(newLine) && isNaN(nextLine)){
  38.         resultStr = `${resultStr}-${nextLine}`;
  39.     }else if(!isNaN(newLine) && isNaN(nextLine)){
  40.         console.log(sum);
  41.         sum = 0;
  42.         resultStr = `${resultStr}-${nextLine}`
  43.     }else if(isNaN(newLine) && !isNaN(nextLine)){
  44.         if(resultStr[0] === '-'){
  45.         console.log(resultStr.slice(1,));
  46.     }else{
  47.         console.log(resultStr);
  48.     }
  49.  
  50.         resultStr = '';
  51.         sum += +nextLine;
  52.     }
  53.     newLine = nextLine
  54. }
  55. if(resultStr[0] === '-'){
  56.     console.log(resultStr.slice(1,));
  57. }else if(resultStr.length != 0){
  58.     console.log(resultStr);
  59. }
  60. if(sum != 0){
  61.     console.log(sum);
  62. }
  63.  
  64. // if(resultStr === ''){
  65. //     resultStr = 'no words';
  66. //     console.log(resultStr);
  67. //     console.log(sum);
  68. // }else{
  69. //     console.log(resultStr.slice(1,));
  70. //     console.log(sum);
  71. // }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement