2018年7月23日 星期一

itsa [C_AR06-易]字串在哪裡

#include<iostream>
#include<string>
using namespace std;

int main()
{
int n = 1, ans = 0, x = 0, y = 1;
int num[4] = { 0 };
int f[8][2] = { {0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1} };
string s, s1;
char arr[22][22];
for (int i = 0; i < 22; i++)
for (int j = 0; j < 22; j++)
arr[i][j] = '0';
getline(cin, s);
if (s.length() > 10)
ans = 1;
while (getline(cin, s1))
{
if (s1.length() > 20)
ans = 2;
else
{
for (int i = 0; i < s1.length(); i++)
arr[n][i + 1] = s1[i];
n++;
}
if (n - 1 == s1.length())
break;
}
if (ans >= 1)
cout << "Target Overflow" << endl;
if (ans == 2)
cout << "Array Overflow" << endl;
if (ans == 0)
{
for (int i = 1; i <= s1.length(); i++)
{
for (int j = 1; j <= s1.length(); j++)
{
x = 0;
if (arr[i][j] == s[0])
{
num[0] = i - 1;
num[1] = j - 1;
while (x < 8)
{
for (int d = 1; d < s.length(); d++)
{
if (arr[i + f[x][0] * d][j + f[x][1] * d] != '0' && arr[i + f[x][0] * d][j + f[x][1] * d] == s[y])
{
y++;
if (y == s.length())
{
num[2] = i + f[x][0] * (s.length() - 1) - 1;
num[3] = j + f[x][1] * (s.length() - 1) - 1;
cout << num[0] << ", " << num[1] << " To " << num[2] << ", " << num[3] << endl;
}
}
else
break;
}
y = 1;
x++;
}
}
}
}
}
return 0;
}

沒有留言:

張貼留言