二维数组操作

#include<iostream>
using namespace std;

int range(int row, int col)
{
    if(row>0 && row<=9)
    {
        if(col>0 && col<=9)
        {
            return 0;
        }
        else
        {
            return -1;
        }
    }
    else
    {
        return -1;
    }
}

int pintmat(int row, int col, int r, int c)
{
    if(r<0 || r>=row)
    {
        return -1;
    }
    if(c<0 || c>=row)
    {
        return -1;
    }
    return 0;
}

int crinmat(int row, int r)
{
    if(r>=0 && r<row)
        return 0;
    else
        return -1;
}

int main()
{
    int row,col;
    cin>>row>>col;
cout<<range(row,col)<<endl;


    int c1,c2,r1,r2;
    cin>>r1>>c1>>r2>>c2;
if(c1==c2 && r1==r2)
    cout<<"-1"<<endl;
else
{
    if(pintmat(row,col, r1, c1)==0 && pintmat(row,col, r1, c1)==0)
    {
        cout<<'0'<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }
}

    int r;
    cin>>r;
cout<<crinmat(row, r)<<endl;

    int c;
    cin>>c;
cout<<crinmat(col, c)<<endl;

    cin>>r>>c;
cout<<pintmat(row, col, r,c)<<endl;

    return 0;
}

  

posted @ 2016-12-30 13:11  Hardsoftware  阅读(150)  评论(0编辑  收藏  举报