Title: Give you a two-dimensional character descriptor, with some letters and *,* and boundaries as delimiters,
Numbering successive positions (top to bottom, left to right) as shown, outputs all horizontal and vertical words.
Parse: String. First in order to find out the number of each square, in addition to the beginning of the word letter, the other is 0;
Then, the horizontal and the bus scan word output can be; (portrait to first sort on output)
NOTES: 1. Note that in order to output the results, there is a blank line between the 2 consecutive outputs.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace std;typedef struct _node{int Id;char str[12];} Node;node Data[101];char maps[12][12];int Size[12][12];int CMP (Node A, Node B) {return a.id < b.id;} int main () {int row,column,times = 1;while (cin >> row && row) {cin >> column;for (int i = 0; i < ro W + i) cin >> maps[i];int id = 1;for (int i = 0; i < row; + + i) for (int j = 0; j < column; + + j) if (Maps[i][j]! = ' * ' && (!i | |!j | | maps[i-1][j] = = ' * ' | | maps[i][j-1] = = ' * ')) size[i][j] = id ++;else size[i][j] = 0;if (time s > 1) printf ("\ n");p rintf ("Puzzle #%d:\n", Times + +);p rintf ("across\n"); for (int i = 0; i < row; + + i) {int move = 0 while (move < column) {if (Size[i][move]) {printf ("%3d.", Size[i][move]); int save = 0;while (Move < column && ; Maps[i][move]! = ' * ') printf ("%c", Maps[i][move + +]);p rintf ("\ n");} else move++;}} printf ("down\n"); int count = 0;for (int i = 0; i < column; + + i) {int move = 0;while (Move < row) {if (Size[move][i] {data[count].id = Size[move][i];int save = 0;while (Move < row && Maps[move][i]! = ' * ') Data[count].str[save + +] = Maps[move ++][i];d ata[count ++].str[save + +] = 0;} else move + +;}} Sort (data, Data+count, CMP), for (int i = 0; i < count; + + i) printf ("%3d.%s\n", Data[i].id, DATA[I].STR);} return 0;}
UVa 232-crossword Answers