网站运营编辑,深圳网站设计美工,wordpress notfound,网站首页幻灯片代码易忽略的错误#xff1a;开始习惯性地看到n就以为是n*n数组了#xff0c;实际上应该是9*9的固定大小数组#xff0c;查了半天没查出来
题面
L1-104 九宫格 - 团体程序设计天梯赛-练习集 代码实现
#includebits/stdc.h
using namespace std;
//易错#xff1a;开…易忽略的错误开始习惯性地看到n就以为是n*n数组了实际上应该是9*9的固定大小数组查了半天没查出来
题面
L1-104 九宫格 - 团体程序设计天梯赛-练习集 代码实现
#includebits/stdc.h
using namespace std;
//易错开始习惯性地看到n就以为是n*n数组了
int main()
{int direct[8][2] {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};int n; cinn;vectorvectorintgraph(9, vectorint(9));//开始习惯性地看到n就以为是n*n数组了vectorintres;int flag 1;setintst;//全部放在一个大for中就好了for(int m0; mn; m){//接收和检验每行for(int i0; i9; i){for(int j0; j9; j){cingraph[i][j];if(graph[i][j]1 || graph[i][j]9) flag 0;//数字均为1~9st.insert(graph[i][j]); }if(st.size() ! 9) flag 0;//每行的检验st.clear();}//每列for(int j0; j9 flag ! 0; j){for(int i0; i9; i){st.insert(graph[i][j]);}if(st.size()!9){flag 0; break;} }//每宫格for(int i1; i9 flag ! 0; i3){for(int j1; j9 flag ! 0; j3)//每宫格的中心点{st.clear();st.insert(graph[i][j]);for(int k0; k8; k){st.insert(graph[idirect[k][0]][jdirect[k][1]]);}if(st.size()!9){flag 0; break;} }}st.clear();res.push_back(flag);flag 1;}for(int i0; ires.size(); i){coutres[i];if(i!res.size()-1) coutendl;}return 0;
}