Comment detail
文字列の八方向検索 (Nested Flatten)方法は殆ど変わってないのですが。 下方向へのチェックだと、入力がファイルや標準入力だった時につぶしがきかない(行を先読みしないといけない)ので、上方向に修正。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | void output(int x, int y, std::string v)
{
std::cout << "(" << x << "," << y << "), " << v.c_str() << std::endl;
}
void search8way(std::vector<std::string> lines, std::string str)
{
if (str.empty() != false)
return;
std::string rstr(str);
std::reverse(rstr.begin(), rstr.end());
int nLen = (int)str.size();
char cs = str[0];
char ce = str[nLen - 1];
for (int y = 0; y < (int)lines.size(); y++)
{
std::string line = lines[y];
for (int x = 0; x < (int)line.size(); x++)
{
if ((line[x] != cs) && (line[x] != ce))
continue;
std::string strLU(""); strLU += line[x];
std::string strUP(""); strUP += line[x];
std::string strRU(""); strRU += line[x];
for (int d = 1; (d < nLen) && ((y - d) >= 0); d++)
{
std::string buff = lines[y - d];
if (((int)buff.size() > (x - d)) && ((x - d) >= 0))
strLU += buff[x - d];
if ((int)buff.size() > x)
strUP += buff[x];
if ((int)buff.size() > (x + d))
strRU += buff[x + d];
}
if (line[x] == cs)
{
if (line.compare(x, nLen, str) == 0)
output(x, y, "右");
if (strLU.compare(str) == 0) { output(x, y, "左上"); }
if (strUP.compare(str) == 0) { output(x, y, "上" ); }
if (strRU.compare(str) == 0) { output(x, y, "右上"); }
}
if (line[x] == ce)
{
if (line.compare(x, nLen, rstr) == 0)
output(x + (nLen - 1), y, "左");
if (strRU.compare(rstr) == 0)
output(x + (nLen - 1), y - (nLen - 1), "左下");
if (strUP.compare(rstr) == 0)
output(x , y - (nLen - 1), "下");
if (strLU.compare(rstr) == 0)
output(x - (nLen - 1), y - (nLen - 1), "右下");
}
}
}
}
|




梅紫蘇
#4612()
[
C++
]
Rating0/0=0.00
全角じゃないけど。反転した比較文字列をつくって、4方向(右方向+下方向)の文字列チェック×2で、8方向...になってるとおもう....orz
Rating0/0=0.00-0+
1 reply [ reply ]