传送门:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=168
当时多输出了一个回车,结果一直WA(不应该是PE的吗/(ㄒoㄒ)/~~)。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
char map[11][11];
int a[11][11];
int main()
{
freopen("1.txt" , "r" , stdin);
int r, c, i, j, k, cnt, ans = 1;
while(scanf("%d", &r), r)
{
scanf("%d", &c);
getchar();
for (i = 0; i < r; i++)
{
gets(map[i]);
}
memset(a, 0, sizeof(a));
if (ans != 1)
{
cout << endl;
}
printf("puzzle #%d:\nAcross\n", ans++);
cnt = 0;
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
if (map[i][j] != '*')
{
if (i == 0 || j == 0 || map[i-1][j] == '*' || map[i][j-1] == '*')
{
printf("%3d.", cnt+1);
for (;j < c; j++)
{
if (map[i][j] == '*')
{
break;
}
if (i == 0 || j == 0 || map[i-1][j] == '*' || map[i][j-1] == '*')
{
cnt++;
a[i][j] = cnt;
}
cout << map[i][j];
}
cout << endl;
}
}
}
}
printf("Down\n");
cnt = 0;
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
if (a[i][j] > 0)
{
printf("%3d.", a[i][j]);
for(k = i; k < r; k++)
{
if (map[k][j] == '*')
{
break;
}
cout << map[k][j];
a[k][j] = -1;
}
cout << endl;
}
}
}
}
return 0;
}