#include #include using namespace std; int main() { int word_length, shift; vector alphabet_map(170, '0'); alphabet_map[109] = 'A'; alphabet_map[110] = 'B'; alphabet_map[111] = 'C'; alphabet_map[4] = 'D'; alphabet_map[30] = 'E'; alphabet_map[56] = 'F'; alphabet_map[82] = 'G'; alphabet_map[136] = 'H'; alphabet_map[137] = 'I'; alphabet_map[2] = 'J'; alphabet_map[5] = 'K'; alphabet_map[31] = 'L'; alphabet_map[57] = 'M'; alphabet_map[83] = 'N'; alphabet_map[163] = 'O'; alphabet_map[6] = 'P'; alphabet_map[32] = 'Q'; alphabet_map[58] = 'R'; alphabet_map[84] = 'S'; alphabet_map[7] = 'T'; alphabet_map[33] = 'U'; alphabet_map[3] = 'V'; alphabet_map[28] = 'W'; alphabet_map[29] = 'X'; alphabet_map[59] = 'Y'; alphabet_map[55] = 'Z'; cin >> word_length >> shift; for(int word_idx = 0; word_idx < word_length; word_idx++) { string line, l1, l2, l3; for (int i = 0; i < 3; ++i) { cin >> line; } //read core of the letter cin >> l1 >> l2 >> l3; for (int i = 0; i < 3; ++i) { cin >> line; } vector directions(8, false); if(l3[4] == '#') directions[4] = true; if(l3[3] == '#') directions[5] = true; if(l2[3] == '#') directions[6] = true; if(l1[3] == '#') directions[7] = true; if(l1[4] == '#') directions[0] = true; if(l1[5] == '#') directions[1] = true; if(l2[5] == '#') directions[2] = true; if(l3[5] == '#') directions[3] = true; int checksum = 0; for (int i = 0; i < 8; ++i) { checksum += directions[i]; } if(checksum != 2) { return 42; } int dir1 = -1, dir2 = -1; for (int i = 0; i < 8; ++i) { if(directions[i]) { if(dir1 == -1) dir1 = i; else if(dir2 == -1) dir2 = i; else return 43; //nacteno vic cisel } } if(dir1 * dir2 < 0) return 44; //nacteno jen jedno cislo if(dir1 == dir2 && dir1 == -1) return 45; //nenacteno zadne cislo if(dir1 == dir2) return 46; int lower_dir = min(dir1, dir2); int higher_dir = max(dir1, dir2); int hash_dir = lower_dir * 26 + higher_dir; char letter = alphabet_map[hash_dir]; char shifted_letter = (char)((((int) letter - 97) + shift % 97) + 97); int shifted = (int)shifted_letter; int higher_shifted_dir = shifted % 26; int lower_shifted_dir = (shifted)/26; if(lower_shifted_dir < 0 || lower_shifted_dir > 7) return 47; if(higher_shifted_dir < 0 || higher_shifted_dir > 7) return 48; if(lower_shifted_dir == higher_shifted_dir) return 49; vector shifted_directions(8, false); for (int i = 0; i < 8; ++i) { if(higher_shifted_dir == i || lower_shifted_dir == i) {shifted_directions[i] = true;} } vector output_matrix(9, "........."); output_matrix[4][4] = '*'; int detected_dirs = 0; if(shifted_directions[4]){ detected_dirs++; output_matrix[5][4] = '#'; output_matrix[6][4] = '#'; output_matrix[7][4] = '#'; } if(shifted_directions[5]) { detected_dirs++; output_matrix[5][3] = '#'; output_matrix[6][2] = '#'; output_matrix[7][1] = '#'; } if(shifted_directions[6]) { detected_dirs++; output_matrix[4][1] = '#'; output_matrix[4][2] = '#'; output_matrix[4][3] = '#'; } if(shifted_directions[7]) { detected_dirs++; output_matrix[3][3] = '#'; output_matrix[2][2] = '#'; output_matrix[1][1] = '#'; } if(shifted_directions[0]) { detected_dirs++; output_matrix[3][4] = '#'; output_matrix[2][4] = '#'; output_matrix[1][4] = '#'; } if(shifted_directions[1]) { detected_dirs++; output_matrix[1][7] = '#'; output_matrix[2][6] = '#'; output_matrix[3][5] = '#'; } if(shifted_directions[2]) { detected_dirs++; output_matrix[4][5] = '#'; output_matrix[4][6] = '#'; output_matrix[4][7] = '#'; } if(shifted_directions[3]) { detected_dirs++; output_matrix[5][5] = '#'; output_matrix[6][6] = '#'; output_matrix[7][7] = '#'; } if(detected_dirs != 2) { return 51; } for (int i = 0; i < 9; ++i) { cout << output_matrix[i] << endl; } } return 0; }