网易 2019校招C++研发工程师笔试卷(有道)编程题-2018.09.08

1
1-2.png
1-3.png

#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n <= 5){
        cout << 1 << endl;
        return 0;
    }
    int res = n/5;
    if(n%5 != 0)
        res++;
    cout << res << endl;
    return 0;
}

2-1.png
2-2.png
2-3.png
这道题是找规律的题,没法详细讲解,只能举例子挨个列出来观察
1. 只要行或者列其中有一个是2,输出0
2. 行或者列都是1,输出1
3. 行或者列其中一个是1,另一个大数大于3的话,输出大数-2
4. 行或列均大于2,除了周围一圈是朝上,其余均朝下,输出row*column - 2*row - 2*column + 4

#include <iostream>
#include <vector>
using namespace std;
void foo(long long row, long long column){
    long long res;
    if(row == 1){
        if(column >= 3)
            res = column - 2;
        if(column == 1)
            res = 1;
    }
    if(column == 1 && row >= 3){
        res = row - 2;
    }
    if(row==2 || column==2){
        res = 0;
    }
    if(row>2 && column>2){
        res = row*column - 2*row - 2*column + 4;

    }
    cout << res << endl;
}
int main()
{
    int t;
    cin >> t;
    for(int i=0; i<t; i++){
        long long row, column;
        cin >> row >> column;
        foo(row, column);
    }
    return 0;
}

3-1.png
3-2.png
3-3.png
3-4.png
后续补代码

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值