File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ const rl = require("readline").createInterface({ input: process.stdin });
2+ var iter = rl[Symbol.asyncIterator]();
3+ const readline = async () => (await iter.next()).value;
4+
5+ void async function () {
6+ const a = (await readline()).split('').map(it => Number(it))
7+ const idxs = a.reduce((s, it, idx) => { // reduce 支持第三个参数 idx
8+ if (it)
9+ s.push(a.length - idx)
10+ return s
11+ }, [])
12+
13+ // 注意特殊情况!!
14+ if (idxs.length === 1) {
15+ console.log('0')
16+ return
17+ }
18+ if (idxs.length === 0) {
19+ console.log('1')
20+ }
21+
22+ // console.log(idxs)
23+ let ans = ''
24+ while (idxs.length > 1) {
25+ let cur = idxs.pop()
26+ // while(ans.length < cur-1){
27+ ans = '0'.repeat((cur - 1) - ans.length) + ans
28+ // }
29+ ans = '1' + ans
30+ while (idxs[idxs.length - 1] === cur + 1) {
31+ idxs.pop()
32+ cur++ // 连锁倾销
33+ }
34+ idxs.push(cur + 1)
35+ }
36+ console.log(ans)
37+ }()
You can’t perform that action at this time.
0 commit comments