题解 | #二维数组操作#

二维数组操作

https://www.nowcoder.com/practice/2f8c17bec47e416897ce4b9aa560b7f4

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    string s;

    while (getline(cin, s)) {
        int m = s[0] - '0', n = s[2] - '0';
        if ((m <= 0 || m > 9) || (n <= 0 || n > 9)) {
            cout << "-1" << endl;
        } else {
            cout << "0" << endl;
        }
        // vector<vector<int>> arr(m,vector<int>(n));

        getline(cin, s);
        int x1 = s[0] - '0', y1 =  s[2] - '0', x2 = s[4] - '0', y2 = s[6] - '0';
        if ((x1 < 0 || x1 >= m) || (x2 < 0 || x2 >= m) || (y1 < 0 || y1 >= n) ||
                (y2 < 0 || y2 >= n)) {
            cout << "-1" << endl;
        } else {
            cout << "0" << endl;
        }
        // int tmp = arr[x1][y1];
        // arr[x1][y1] = arr[x2][y2];
        // arr[x2][y2] = tmp;

        getline(cin, s);
        int x = s[0] - '0';
        if ((x < 0 || x >= m) || (m + 1 > 9)) {
            cout << "-1" << endl;
        } else {
            cout << "0" << endl;
        }

        getline(cin, s);
        int y = s[0] - '0';
        if ((y < 0 || y >= n) || (n + 1 > 9)) {
            cout << "-1" << endl;
        } else {
            cout << "0" << endl;
        }

        getline(cin,s);
        x1 = s[0] - '0';
        y1 =  s[2] - '0';
        if((x1 < 0 || x1 >= m) || (y1 < 0 || y1 >= n)){
            cout << "-1" << endl;
        }else{
            cout << "0" << endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

注意对题目意思的理解,题目应该只是要求看这个操作是否合法,并不需要实际去执行这个操作。

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-02 17:58
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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