fork download
  1. const readline = require('readline');
  2.  
  3. const rl = readline.createInterface({
  4. input: process.stdin,
  5. output: process.stdout
  6. });
  7.  
  8. let arr;
  9. const init = val => arr = Array.apply(null, Array(20)).map(() => val);
  10.  
  11. (async() => {
  12. init(false);
  13. for await (let line of rl) {
  14. let [proc, k] = line.split(" ");
  15. k = parseInt(k) - 1;
  16. if (proc === "add") arr[k] = 1;
  17. if (proc === "remove") arr[k] = 0;
  18. if (proc === "check") console.log(arr[k] | 0);
  19. if (proc === "toggle") arr[k] = !arr[k];
  20. if (proc === "all") init(true);
  21. if (proc === "empty") init(false);
  22. }
  23. })();
  24.  
Success #stdin #stdout #stderr 0.08s 36672KB
stdin
26
add 1
add 2
check 1
check 2
check 3
remove 2
check 1
check 2
toggle 3
check 1
check 2
check 3
check 4
all
check 10
check 20
toggle 10
remove 20
check 10
check 20
empty
check 1
toggle 1
check 1
toggle 1
check 1
stdout
1
1
0
1
0
1
0
1
0
1
1
0
0
0
1
0
stderr
(node:32016) ExperimentalWarning: readline Interface [Symbol.asyncIterator] is an experimental feature. This feature could change at any time
(node:32016) ExperimentalWarning: Readable[Symbol.asyncIterator] is an experimental feature. This feature could change at any time