#include #include char *fragments[8][8] = { { ".......", ".......", ".......", "...*...", "...#...", "...#...", "...#...", }, { ".......", ".......", ".......", "...*...", "..#....", ".#.....", "#......", }, { ".......", ".......", ".......", "###*...", ".......", ".......", ".......", }, { "#......", ".#.....", "..#....", "...*...", ".......", ".......", ".......", }, { "...#...", "...#...", "...#...", "...*...", ".......", ".......", ".......", }, { "......#", ".....#.", "....#..", "...*...", ".......", ".......", ".......", }, { ".......", ".......", ".......", "...*###", ".......", ".......", ".......", }, { ".......", ".......", ".......", "...*...", "....#..", ".....#.", "......#", }, }; int pairs[26][2] = { {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {0, 7}, {1, 2}, {1, 3}, {4, 6}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {3, 4}, {3, 5}, {4, 7}, {5, 6}, {5, 7}, {3, 6}, {6, 7}, }; int registerP(int * pair, int n) { //printf("reg req: %d\n", n); if(pair[0] == -1) { pair[0] = n; return 1; } if(n == pair[0]) return 1; pair[1] = n; return 2; } char decodeChar(char ** encoded) { //printf("%x...\n", encoded); // for(int i = 0; i < 9; i++) printf("%d: %s\n", i, encoded[i]); int detectedPair[2] = {-1, -1}; for(int j = 1; j < 8; j+=3) { if( j == 1 ) { //printf("match:1\n"); // match 3, 4, 5 if(encoded[j][1] == '#') { if(registerP(detectedPair, 3) > 1) break; } if(encoded[j][4] == '#') { if(registerP(detectedPair, 4) > 1) break; } if(encoded[j][7] == '#') { if(registerP(detectedPair, 5) > 1) break; } } else if(j == 4) { //printf("match:2\n"); // match 2, 6 if(encoded[j][1] == '#') { if(registerP(detectedPair, 2) > 1) break; } if(encoded[j][7] == '#') { if(registerP(detectedPair, 6) > 1) break; } } else if(j == 7) { //printf("match:3\n"); // match 1, 0, 7 if(encoded[j][1] == '#') { if(registerP(detectedPair, 1) > 1) break; } if(encoded[j][4] == '#') { if(registerP(detectedPair, 0) > 1) break; } if(encoded[j][7] == '#') { if(registerP(detectedPair, 7) > 1) break; } } } //printf("sort...\n"); //printf("P: %d %d\n", detectedPair[0], detectedPair[1]); if(detectedPair[0] > detectedPair[1]) { int tmp = detectedPair[0]; detectedPair[0] = detectedPair[1]; detectedPair[1] = tmp; } //printf("search...\n"); //printf("P: %d %d\n", detectedPair[0], detectedPair[1]); for(int i = 0; i < 26; i++) { if(pairs[i][0] == detectedPair[0] && pairs[i][1] == detectedPair[1]) return i + 'A'; } return 0; } void encodeChar(char c) { //printf("%c, %d", c, c - 'A'); int * pair = pairs[c - 'A']; printf(".........\n"); for(int i = 0; i < 7; i++) { for( int j = 0; j < 9; j++) { if(j == 0 || j == 8) printf("."); else if(fragments[pair[0]][i][j-1] == '#' || fragments[pair[1]][i][j-1] == '#') printf("#"); else if(fragments[pair[0]][i][j-1] == '*') printf("*"); else printf("."); } printf("\n"); } printf(".........\n"); } int main() { unsigned int N, C; char ** letter = malloc(sizeof(char *) * 9); for (int i = 0; i < 9; i++) { letter[i] = malloc(sizeof(char) * 15); } int a = scanf("%u %u\n", &N, &C); for(int i = 0; i < N; i++) { for(int j = 0; j < 9; j++) { //printf("%d: %x\n", j, letter[j]); a = fgets(letter[j], 13, stdin); } //printf("%x...\n", letter[0]); char result = decodeChar(letter) + C; if(result > 'Z') result -= 26; encodeChar(result); } for (int i = 0; i < 9; i++) { free(letter[i]); } free(letter); }