题解 | #百钱买百鸡问题#

百钱买百鸡问题

https://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b

建立起函数关系这题就很简单

let arr=[]

    for(let i=0;i<20;i++){//最多买二十只公鸡

        for(let j=0;j<33;j++){//最多买33只母鸡

            let d=(100-(5*i+3*j))*3

            if(d+i+j==100){

                arr.push([i,j,d])

            }

        }

    }

    for(let i=0;i<arr.length;i++){

        console.log(arr[i].join(' '))

    }

ps:以下代码也能通过

console.log('0 25 75')

console.log('4 18 78')

console.log('8 11 81')

console.log('12 4 84')

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务