这就是我必须寻找的单词&在for循环内的其他方向(N,S等)重复完全相同(我没有包括它的长度)除了我有rowBlock和colBlock +run或-run :
for (int rowBlock = 0; rowBlock < 18; rowBlock++) {
for (int colBlock = 0; colBlock < 18; colBlock++) {
if (string(1, namesToSearch[i][0]) == (wordSearchBlock[rowBlock][colBlock])) {
PsblRow = rowBlock;
PsblCol = colBlock;
//checking in the NW direction
for (int run = 1; run <= namesToSearch[i].length(); run++) {
if (string(1, namesToSearch[i][1]) == (wordSearchBlock[rowBlock - run][colBlock - run]) && (rowBlock - run) >= 0 && (colBlock - run) >= 0) {
direction = "NW";
if (run = namesToSearch[i].length()) {
cout << movieName << " found at " << PsblRow << ", " << PsblCol << ": (direction = " << direction << ")" << endl;
wordExists++;
}
}
else {
break;
}
}
}
}
给出一些上下文:namesToSearch 是一个字符串向量,而 wordSearchBlock 是一个数组 [18][18] 请帮助我!!我不知道出了什么问题,这是我不断得到的输出示例:
ALL OF ME found at 2, 9: (direction = NE)
ALL OF ME found at 2, 17: (direction = N)
ALL OF ME found at 2, 17: (direction = N)
ALL OF ME found at 2, 17: (direction = SE)
ALL OF ME found at 5, 3: (direction = SE)
ALL OF ME found at 5, 3: (direction = SE)
ALL OF ME found at 5, 6: (direction = S)
ALL OF ME found at 5, 6: (direction = S)
ALL OF ME found at 5, 12: (direction = W)
ALL OF ME found at 5, 12: (direction = W)
ALL OF ME found at 5, 12: (direction = SE)
ALL OF ME found at 5, 12: (direction = SE)
ALL OF ME found at 6, 0: (direction = N)
ALL OF ME found at 6, 0: (direction = N)
ALL OF ME found at 6, 0: (direction = SE)
ALL OF ME found at 7, 7: (direction = NW)
ALL OF ME found at 7, 7: (direction = W)
ALL OF ME found at 7, 7: (direction = W)
ALL OF ME found at 8, 0: (direction = NE)
ALL OF ME found at 8, 4: (direction = NE)
ALL OF ME found at 8, 4: (direction = NE)
ALL OF ME found at 8, 4: (direction = E)
ALL OF ME found at 8, 17: (direction = SE)
ALL OF ME found at 9, 9: (direction = SW)
ALL OF ME found at 9, 9: (direction = S)
ALL OF ME found at 10, 14: (direction = NE)
ALL OF ME found at 10, 17: (direction = NE)
ALL OF ME found at 10, 17: (direction = W)
ALL OF ME found at 11, 11: (direction = W)
ALL OF ME found at 11, 11: (direction = E)
ALL OF ME found at 11, 11: (direction = SW)
ALL OF ME found at 11, 15: (direction = NE)
ALL OF ME found at 11, 16: (direction = N)
ALL OF ME found at 12, 11: (direction = NW)
ALL OF ME found at 12, 11: (direction = NE)
ALL OF ME found at 12, 11: (direction = W)
ALL OF ME found at 12, 13: (direction = NW)
ALL OF ME found at 13, 17: (direction = NE)
ALL OF ME found at 15, 14: (direction = S)
ALL OF ME found at 15, 15: (direction = SW)
ALL OF ME found at 15, 15: (direction = SW)
实际位置在8,4。