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

版权声明:本人ZZU在校学生,文章均为个人心得,有不足之处请不吝赐教! https://blog.csdn.net/whl_program/article/details/82531804

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
后续补代码

猜你喜欢

转载自blog.csdn.net/whl_program/article/details/82531804