字符串系列――10010 Where's Waldorf?(二)
j < m; j ++)
{
for (l = 0; l < n; l ++)
{
if (word[i][0] == letter[j][l])
{
if (l + len <= n)
{
if (j - len + 1 >= 0)
{
//ru
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j + p][l - p];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
if (j + len <= m)
{
//rd
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j + p][l + p];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
//r
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j + p][l];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
if (l - len + 1 >= 0)
{
if (j - len + 1 >= 0)
{
//lu
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j - p][l - p];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
if (j + len <= m)
{
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j - p][l + p];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
//l
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j - p][l];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
if (j - len + 1 >= 0)
{
//u
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j][l - p];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
if (j + len <= m)
{
//d
memset(temp, 0, sizeof(temp));
for (int p = 0; p < len; p++)
temp[p] = letter[j][l + p];
if (strcmp(temp, word[i]) == 0)
{
rec_n = j;
rec_m = l;
return 0;
}
}
}
}
}
rec_m = rec_n = 0;
return 0;
}
这样看来的确又臭又长。。。
而且以上代码虽然结果和例子一样,但却ac不了。。。
后来找刷过的朋友问了下原来里面有每组之间空行的条件。这种错误是第几次了。。。
用if判断一下,还是ac不了。
后来那别人的代码来测试对比,发现逻辑有错误,我原来的做法是:找到字符后,用行列的加减判断是否可以按那个方向排字符串,再录入字符串用strcmp进行判断,因为我觉得letter[-1][-3]这种数组会出错(证实不会,人家会空着)。。。
结果判断时出错了,搞了好