题解 | #二维数组操作#
二维数组操作
http://www.nowcoder.com/practice/2f8c17bec47e416897ce4b9aa560b7f4
思路
1.主要时判断行列的范围是否有效
Answer
#include<stdio.h>
void initexcel(int m,int n){//初始化表格
if(m>9||n>9)
printf("-1\n");
else
printf("0\n");
}
void change(int m,int n,int x1,int y1,int x2,int y2){//交换
if(x1<0||x2<0||y1<0||y2<0)
printf("-1\n");
else if(x1>=m||x2>=m||y1>=n||y2>=n)
printf("-1\n");
else
printf("0\n");
}
void insert_C(int m,int x){//插入行
if(m+1>9||x>=m)
printf("-1\n");
else
printf("0\n");
}
void insert_R(int n,int y){//插入列
if(n+1>9||y>=n)
printf("-1\n");
else
printf("0\n");
}
void seek(int m,int n,int x,int y){//查找
if(x>=m||x<0||y>=n||y<0)
printf("-1\n");
else
printf("0\n");
}
int main(){
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
{
initexcel(m,n);
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
change(m,n,x1, y1, x2, y2);
int x;
scanf("%d",&x);
insert_C(m,x);
int y;
scanf("%d",&y);
insert_R(n,y);
int x3,y3;
scanf("%d %d",&x3,&y3);
seek(m,n,x3,y3);
}
return 0;
}