题解 | #二维数组操作#

二维数组操作

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

题目说的还是清楚的啊,它只是想让你做个简单的判断而已啊,哈哈,注意输入的行列不是索引也就是说输入9行9列,但它的索引是0-8。插入的时候只有小于9行9列的才可以插入。

```#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int m,n;
    vector<int> res;
    while(cin>>m>>n){
        if(m>=1&&(m<=9)&&(n>1)&&(n<=9)) res.push_back(0);//它输入的行数列数,//一定是可以成立的
//不然不成立下面那些操作都应该是-1,但是明显样例里面没有超出的行数列数。
      int x1,x2,y1,y2,row,col,coodx,coody;
        
        cin>>x1>>y1>>x2>>y2;
        if((x1>=0)&&(x1<=m-1)&&(y1>=0)&&(y1<=n-1)&&
          (x2>=0)&&(x2<=m-1)&&(y2>=0)&&(y2<=n-1)) res.push_back(0);
        else res.push_back(-1);
        cin>>row;
        if(row>=0&&(row<=m-1)&&m<9) res.push_back(0);
        else res.push_back(-1);
        cin>>col;
        if(col>=0&&(col<=n-1)&&n<9) res.push_back(0);
        else res.push_back(-1);
        cin>>coodx>>coody;
        if(coodx>=0&&coodx<=m-1&&coody>=0&&coody<=n-1)
            res.push_back(0);
        else res.push_back(-1);
        for(auto it = res.begin();it!=res.end();it++){
            cout<<(*it)<<endl;
        }
        res.clear();
    }
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务