📄 1987.cpp
字号:
#include <iostream>
using namespace std;
char c[22][22];
char word[88];
bool hash[22][22];
int main()
{
int tests, k;
scanf("%d", &tests);
for (k = 1; k <= tests; k++)
{
int n, m, x, y, a, b, i, j, ca, num, direct;
memset(c, 0, sizeof(c));
memset(hash, false, sizeof(hash));
scanf("%d %d ", &n, &m);
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
scanf("%c", &c[i][j]);
}
}
direct = 0;
num = m * n / 5;
cout << k << " ";
x = 0, y = 0;
for (ca = 0; ca < num; ca++)
{
int ss = 0;
for (i = 4; i >= 0; i--)
{
hash[y][x] = true;
int to;
if (i == 4)
{
to = 16;
}
else if (i == 3)
{
to = 8;
}
else if (i == 2)
{
to = 4;
}
else if (i == 1)
{
to = 2;
}
else if (i == 0)
{
to = 1;
}
ss += (c[y][x] - '0') * to;
a = x, b = y;
if (direct == 0)
{
a++;
}
else if (direct == 1)
{
b++;
}
else if (direct == 2)
{
a--;
}
else if (direct == 3)
{
b--;
}
if (hash[b][a] == true || a >= m || b >= n || a < 0 || b < 0)
{
a = x, b = y;
direct = (direct + 1) % 4;
if (direct == 0)
{
a++;
}
else if (direct == 1)
{
b++;
}
else if (direct == 2)
{
a--;
}
else if (direct == 3)
{
b--;
}
}
x = a, y = b;
if (i == 0)
{
break;
}
}
if (ss == 0)
{
word[ca] = ' ';
}
else
{
char c = 'A' + ss - 1;
word[ca] = c;
}
}
for (i = num - 1; i >=0; i--)
{
if (word[i] != ' ')
{
break;
}
}
for (j = 0; j <= i; j++)
{
cout << word[j];
}
cout << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -