function a(all){ var i = 0, sum = 6; while(all>0){ all -= sum; if(all <=0 ){ var c= 3+i, b=2+i, a=1+i; if(all+c >= 0){ return "c" }else if(all+c+b >=0){ return "b" } else { return "a" } } i++; sum =+3 } } console.log(a(1111))
趣味题:A,B,C 三个人,第一轮,A拿1个苹果、B拿2个苹果、C拿3个苹果,第二轮每个人加1,以此类推,共1111个苹果,最后一个苹果在谁手上?
//A,B,C 三个人,第一轮,A拿1个苹果、B拿2个苹果、C拿3个苹果,第二轮每个人加1,以此类推,共1111个苹果,最后一个苹果在谁手上?
function a(all){ var i = 0, sum = 6; while(all>0){ all -= sum; if(all <=0 ){ var c= 3+i, b=2+i, a=1+i; if(all+c >= 0){ return "c" }else if(all+c+b >=0){ return "b" } else { return "a" } } i++; sum =+3 } } console.log(a(1111))
function a(all){ var i = 0, sum = 6; while(all>0){ all -= sum; if(all <=0 ){ var c= 3+i, b=2+i, a=1+i; if(all+c >= 0){ return "c" }else if(all+c+b >=0){ return "b" } else { return "a" } } i++; sum =+3 } } console.log(a(1111))