所以这是一种遍历字符矩阵以在字典文件中查找特定单词的方法。当前的问题是下面指出的错误访问....造成这种情况的原因是 d2 = 像一百万并且 l 也等于数十万的值....但是,我的限制显然甚至没有接近......
void Puzzle:: algorithm2(){
int numberofwords = 0;
for (int r = 0; r<Rows; r++) {
for (int c = 0; c<Columns; c++){
for (int d1 = -1; d1<=1; d1++){
for (int d2 = -1; d2<=1; d2++){
//42 ~ 30(2)^0.5
for (int l = dictionary.getminlength(); l<30; l++) {
if (d1==d2==0){
continue;
}
else if ((r+(d1*l))>30||(c+(d2*l))>30||(c+(d2*l))<0||(r+(d1*l))<0){
break;
}
else{
string tempword = "";
for (int p = 0; p<l+1; p++) {
tempword[p] = TheBoard[r+(d1*p)][c+(d2*p)];//badacces
if(dictionary.BinarySearch(tempword)){
cout << "Found " << tempword << " at (" << r << "," << c << ") to (" << r+d1*(int)tempword.length() << "," << c+d2*(int)tempword.length() << ")" << endl;
numberofwords++;
}
}
}
}
}
}
}
}
cout << numberofwords << "words" << endl;
}