4月16网易笔试

### 算法一:画O字
function shengchengO(n) {
    let len = n * 4
    for(let i = 1; i <= len; i++){
        let row = Math.ceil(i / n)
        let line = ""
        for(let j = 1; j <= len; j++) {
            if(row == 1) {
                if( j <= n - i + 1) {
                    line += '.'
                } else if(j >= 3 * n + i) {
                    line += '.'
                } else {
                    line += '*'
                }
            } else if(row == 4) {
                if( j <= ( i - 1 ) % n + 1 ) {
                    line += '.'
                } else if(j > len - (( i - 1 ) % n + 1 )) {
                    line += '.'
                } else {
                    line += '*'
                }
            } else {
                let col = Math.ceil(j / n)
                if(col == 1) {
                    line += '*'
                } else if(col == 4) {
                    line += "*"
                } else {
                    line += "."
                }
            }
        }
        console.log(line)
    }
}
shengchengO(10)
### 算法二:
> 要求输入一个长度为n的不重复数组,且里面的值不超过k,和为x(大概是这个意思~)
示例:
输入
> 4 6 15
输出:
> 1 3 5 6
function zuidaArrFn(n,k,x){
    let count = 0
    let set = new Set()
    let arr = []
    for(let i = 1; i <= n; i++) {
        set.add(i)
        arr.push(i)
    }
    let index = arr.length - 1
    let sum = arr.reduce((pre,cur) => pre + cur,0)
    while(count < x - sum && index >= 0) {
        if(arr[index] < k && !set.has(arr[index] + 1)) {
            set.delete(arr[index])
            arr[index] = arr[index] + 1
            count++
            set.add(arr[index])
        } else {
            index--
        }
    }
    if(index >= 0) {
        return arr.join(' ')
    } else {
        return -1
    }
}
console.log(zuidaArrFn(4,6,15));
### 第三题:一道图的题目
没做
### 第四题求权重和
> 输入长度为3,输入数组数字为[10,2,5],权重就是尾数的数字0的个数,求权重和
> [1,1] 对应10 权重1
> [1,2] 对应20 权重1
> [1,3] 对应100 权重2
> [2,2] 对应2 权重0
> [2,3] 对应10 权重1
> [3,3] 对应5 权重为0
暴力超时:
function quanCount(n,arr) {
    const zeroCount = function(num) {
        let count = 0
        while(true) {
            num = num / 10
            if(num >=1) {
                count++
            } else {
                break;
            }
        }
        return count
    }
    let res = 0
    for(let i = 0;i < n;i++){
        for(let j = i;j<n;j++){
            let tempArr = arr.slice(i,j+1)
            let sum = tempArr.reduce((pre,cur) => pre * cur,1)
            res = res + zeroCount(sum)
        }
    }
    return res
}
console.log(quanCount(3,[10,2,5]));



#春招##实习##笔试题目#
全部评论
网易现在是上机吗?
点赞 回复 分享
发布于 2022-04-18 23:34

相关推荐

10-29 22:30
吉林大学 Java
同专业学长学姐,去互联网大厂的起薪&nbsp;15k+,去国企&nbsp;IT&nbsp;岗的也有&nbsp;12k+,就连去中小厂的都基本&nbsp;13k&nbsp;起步😤&nbsp;我投的传统行业技术岗,拼死拼活拿到&nbsp;1Woffer,本来还挺开心,结果逛了圈牛客直接破防,同是校招生,行业差距怎么就这么大啊!
喵喵喵6_6:应该哪里不对吧,大厂都是20k以上的,10k那种对于985本的学生基本就是点击一下过了笔试就送的,我前两天刚拿了一个11k,笔试完第2天就打电话了,非科班。坏消息是c++岗开这么低真是刷新认知了
校招生月薪1W算什么水平
点赞 评论 收藏
分享
叁六玖:不买课还想秋招
点赞 评论 收藏
分享
评论
3
6
分享

创作者周榜

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