V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  GAMEKON  ›  全部回复第 2 页 / 共 2 页
回复总数  27
1  2  
@TomatoYuyuko 是的,但是任何东西塞多了都会炸,所以后台做了限制了。
可惜这是公开的 notebook
前端是 Summernote,后台是 nodejs。
你看我做的这个行吗?
http://ws.gamekon.com/notepad/
2018-04-27 12:56:33 +08:00
回复了 rwdy2008 创建的主题 程序员 一道有趣的编程题
```

export default class EatingBread
{
a:Array<number> = [];
n:number = 0;

constructor(arg)
{
this.n = parseInt(arg);
this.eat(this.n);
}

eat(i:number):void
{
if (i==0 && this.sum()==this.n)
console.log(this.a);
else if (i==1)
{
this.a.push(1);
this.eat(i - 1);
this.a.pop();
}
else
{
this.a.push(1);
this.eat(i - 1);
this.a.pop();
this.a.push(2);
this.eat(i - 2);
this.a.pop();
}
}

sum():number
{
let s = 0;
for (let i in this.a)
s+=this.a[i];
return s;
}
}

new EatingBread(8);

```
2018-04-27 12:47:49 +08:00
回复了 rwdy2008 创建的主题 程序员 一道有趣的编程题
export default class EatingBread
{
a:Array<number> = [];
n:number = 0;

constructor(arg)
{
this.n = parseInt(arg);
this.eat(this.n);
}

eat(i:number):void
{
if (i==0 && this.sum()==this.n)
console.log(this.a);
else if (i==1)
{
this.a.push(1);
this.eat(i - 1);
this.a.pop();
}
else
{
this.a.push(1);
this.eat(i - 1);
this.a.pop();
this.a.push(2);
this.eat(i - 2);
this.a.pop();
}
}

sum():number
{
let s = 0;
for (let i in this.a)
s+=this.a[i];
return s;
}
}

new EatingBread(8);
1  2  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5628 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 17ms · UTC 02:08 · PVG 10:08 · LAX 19:08 · JFK 22:08
Developed with CodeLauncher
♥ Do have faith in what you're doing.