poj1244

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
#include
<algorithm>
using namespace std;

#define maxn 15

struct Point
{
int x, y;
Point()
{}
Point(
int xx, int yy): x(xx), y(yy)
{}
};

int n, tot;
char map[maxn][maxn];
char ans[maxn * maxn];

void input()
{
getchar();
for (int i = 0; i < n; i++)
for (int j = 0; j <= i; j++)
map[i][j]
= getchar();
}

void work(Point a, Point b, Point c)
{
Point p
= a;
while (!(c.x == p.x && c.y == p.y))
{
if (map[a.x][a.y] == map[b.x][b.y] && map[b.x][b.y]== map[c.x][c.y])
ans[tot
++] = map[a.x][a.y];
a.x
++;
b.y
++;
c.x
--;
c.y
--;
}
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &n), n)
{
input();
tot
= 0;
for (int size = n; size > 1; size--)
for (int i = 0; i <= n - size; i++)
for (int j = 0; j <= i; j++)
work(Point(i, j), Point(i
+ size - 1, j), Point(i + size - 1, j + size - 1));
sort(ans, ans
+ tot);
tot
= unique(ans, ans + tot) - ans;
ans[tot]
= '\0';
if (tot)
printf(
"%s\n", ans);
else
printf(
"LOOOOOOOOSER!\n");
}
return 0;
}
原文地址:https://www.cnblogs.com/rainydays/p/2137475.html