jeudi 26 février 2015

error of vector subscript out of range in c++


well this is the code im getting this error by ...can you guide me? its gonna check a sudoku puzzle... has no compilation error and the build is successful but still gets this error ...i cant get it iv been checking this way of passing my vector to functions but still dont see any mistake in it ...



#include<iostream>
#define nine 9
#include<vector>
using namespace std;
bool row_col_check(vector<vector<char> > &a,int row,int col)
{
int i,j;
char temp=a[row][col];
for(i=0;i<nine;i++)
{
if ((a[row][i]==temp)||(a[i][col]==temp)||(a[row][i]=='#')||(a[i][col]=='#'))
{
return false;
break;
}
}
}
bool square_check(vector<vector<char> > &a,int row,int col)
{
int row_start;
int col_start;
if (row%3==0)
row_start=3;
else
row_start=row%3;
if (col%3==0)
col_start=3;
else
col_start=col%3;
char temp=a[row][col];
for (int check=row-row_start;check<3+row-row_start;check++)
{
for (int check2=col-col_start;check2<3+col-col_start;check2++)
{
if((a[check][check2]==temp)||(a[check][check2]=='#'))
{
return false;
check=check2=3;
}
}
}
}
bool check_func(vector<vector<char> > &a,int row,int col)//checks the row and the column of each number
{
if ((row_col_check)&&(square_check))
return true;
else return false;
}

bool get_sudo(vector<vector<char> >sudo)//reads all number in the puzzle
{
for (int i=0;i<nine;i++)
{
for(int j=0;j<nine;j++)
{
if( check_func(sudo,i,j))
{
continue;
}
else return check_func(sudo,i,j);
break;
}
}
}

int main(){
int n;
vector<vector<char> >puzzle;
cin>>n;
while(n>0)
{
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
cin>>puzzle[i][j];
}
}
if( get_sudo(puzzle))
cout<<true;
if(!get_sudo(puzzle))
cout<<false;
n--;
}
return 0;
}



Aucun commentaire:

Enregistrer un commentaire