题解 | #Number Steps#

Number Steps

https://www.nowcoder.com/practice/e3d8d4dd9ec740f9b1e7fc1e8574ba21

//数学归纳法归纳每个数字的位置以及对于的数字
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

int searchCoor(int x,int y){
    if(x == y){
        return x%2==1 ? x+y-1:x+y;
    }else if (x-2>=0 &&x-2 == y) {
        return x%2==1 ? x+y-1:x+y;
    }else{
        return -1;
    }
}
int main() {
    int a,b,n;
    while (cin >> a >> b) { // 注意 while 处理多个 case
        if(searchCoor(a, b) ==-1) cout<<"No Number";
        else cout << searchCoor(a, b) << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

牛至超人:把哈工大,再加大加粗,看见闪闪发光的哈工大字样,面试官直接流口水
投递字节跳动等公司6个岗位
点赞 评论 收藏
分享
A_SOUL_Off...:疑似加班加出幻觉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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