1 #include <iostream> 2 #include <sstream> 3 #include <string> 4 #include <algorithm> 5 #include <map> 6 #include <vector> 7 using namespace std; 8 9 #define GI ({int _t; scanf("%d", &_t); _t;}) 10 #define FOR(i, a, b) for (int i=a; i<b; i++) 11 #define REP(i, a) FOR(i, 0, a) 12 template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();} 13 int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} 14 #define DBG(x) cout << #x << "::" << x << endl; 15 #define DBGV(_v) { REP(_i, _v.size()) { cout << _v[_i] << "\t";} cout << endl;} 16 17 int main() { 18 int x, y; 19 string t, t2; 20 int kase = 0; 21 bool first = true; 22 while (scanf("%d%d", &x, &y) != -1) { 23 if (x==0 || y==0) break; 24 if (first == false) printf("\n"); 25 first = false; 26 kase++; 27 printf("puzzle #%d:\n", kase); 28 vector <string> cross, lookup; 29 map <int, string> across, down; 30 REP(i, x) { 31 cin >> t; 32 cross.push_back(t); 33 } 34 lookup = cross; 35 //Mark the numbere here... 36 int num = 1; 37 REP(i, cross.size()) { 38 REP(j, cross[i].size()) { 39 if (cross[i][j] != '*' && (i==0 || j==0 || cross[i-1][j] == '*' || cross[i][j-1] == '*')) { 40 lookup[i][j] = num; 41 num++; 42 } 43 else { 44 lookup[i][j] = 0; 45 } 46 } 47 } 48 /* 49 REP(i, lookup.size()) { 50 REP(j, lookup[i].size()) { 51 printf("%d ", lookup[i][j]); 52 } 53 printf("\n"); 54 } 55 */ 56 string word = ""; 57 int start = 0; 58 REP(i, cross.size()) { 59 REP(j, cross[i].size()) { 60 if (cross[i][j] != '*') { 61 if(word.size() == 0) start = j; 62 num++; 63 word += cross[i][j]; 64 65 66 } 67 else if (word.size() > 0){ 68 //printf("%3d. %s\n", lookup[i][start], word.c_str()); 69 across[lookup[i][start]] = word; 70 word = ""; 71 start = num+1; 72 } 73 } 74 if (word.size() > 0) { 75 //printf("%3d. %s\n", lookup[i][start], word.c_str()); 76 across[lookup[i][start]] = word; 77 word = ""; 78 start = num+1; 79 } 80 } 81 82 word = ""; 83 start = 0; 84 REP(j, cross[0].size()) { 85 REP(i, cross.size()) { 86 if (cross[i][j] != '*') { 87 if(word.size() == 0) start = i; 88 num++; 89 word += cross[i][j]; 90 91 92 } 93 else if (word.size() > 0){ 94 //printf("%3d. %s\n", lookup[start][j], word.c_str()); 95 down[lookup[start][j]] = word; 96 word = ""; 97 start = num+1; 98 } 99 100 } 101 if (word.size() > 0) { 102 //printf("%3d. %s\n", lookup[start][j], word.c_str()); 103 down[lookup[start][j]] = word; 104 word = ""; 105 start = num+1; 106 } 107 } 108 printf("Across\n"); 109 for (map<int, string>::iterator it = across.begin(); it != across.end(); it++) { 110 printf("%3d.%s\n", it->first, it->second.c_str()); 111 } 112 printf("Down\n"); 113 for (map<int, string>::iterator it = down.begin(); it != down.end(); it++) { 114 printf("%3d.%s\n", it->first, it->second.c_str()); 115 } 116 //printf("\n"); 117 } 118 return 0; 119 }