UVA 232-Crossword Answers
题目大意: 给个二维数组表,*为分割,分别横向和纵向输出
解题思路:遍历编号,非首字母编为0
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
int main() {
int m, n;
int t = 0;
char c[15][15];
int s[15][15];
while(1) {
t++;
int count = 1;
cin >> m;
if(m == 0)
return 0;
cin >> n;
getchar();
for(int i = 0; i < m; i++) {
for(int y = 0; y <= n; y++) {
c[i][y] = getchar();
}
}
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++) {
if(c[i][j] == '*')
continue;
else if((i - 1) < 0 ||(j - 1) < 0 || c[i-1][j] == '*' || c[i][j-1] == '*')
s[i][j] = count++;
}
if(t > 1)
printf("\n");
printf("puzzle #%d:\n", t);
printf("Across\n");
for(int x = 0; x < m; x++)
for(int y = 0; y < n;) {
if(c[x][y] == '*') {
y++;
continue;
}
if(s[x][y] > 9)
printf(" %d.", s[x][y]);
else
printf(" %d.", s[x][y]);
for(;c[x][y] != '*' && y < n; y++)
printf("%c", c[x][y]);
printf("\n");
}
printf("Down\n");
for(int x = 0; x < m; x++)
for(int y = 0; y < n; y++) {
if(c[x][y] == '*' || s[x][y] == 0)
continue;
if(s[x][y] > 9)
printf(" %d.", s[x][y]);
else
printf(" %d.", s[x][y]);
for(int k = x; k < m; k++) {
if(c[k][y] == '*')
break;
else {
printf("%c", c[k][y]);
s[k][y] = 0;
}
}
printf("\n");
}
}
return 0;
}