Created
November 19, 2015 07:41
-
-
Save 30mb1/b35ccacd435792916a25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <vector> | |
void Rcage(int (&cage)[9][9], const int n) { //функция поворота решетки(матрицы) по часовой | |
int buffcage[9][9]; | |
for (auto i = 1; i <= n; i++) { | |
for (auto j = 1; j <= n; j++) { | |
buffcage[i][j] = cage[n + 1 - j][i]; | |
} | |
} | |
for (auto j = 1; j <= n; j++) { | |
for (auto i = 1; i <= n; i++) { | |
cage[j][i] = buffcage[j][i]; | |
} | |
} | |
} | |
int main() { | |
int n; | |
std::cin >> n; | |
getchar(); | |
int cage[9][9]; | |
std::string line; | |
for (auto i = 1; i <= n; i++) { //считываем решетку. 1 - прорезь. | |
getline(std::cin, line); | |
int j = 1; | |
for (auto z : line) { | |
if (z == '*') { | |
cage[i][j] = 0; | |
} else { | |
cage[i][j] = 1; | |
} | |
j++; | |
} | |
} | |
std::string codeword; | |
getline(std::cin, codeword); | |
char Code[9][9]; | |
auto it = codeword.begin(); | |
std::string partW; | |
std::vector<std::string> word; | |
for (auto i = 1; i <= n; i++) { //считываем закодированное слово и расставляем буквы в решетку. | |
for (auto j = 1; j <= n; j++) { | |
Code[i][j] = *it; | |
++it; | |
} | |
} | |
for (auto i = 1; i <= 4; i++) { //крутим решетку и записываем буквы из прорезей. | |
Rcage(cage, n); | |
for (auto m = 1; m <= n; m++) { | |
for (auto k = 1; k <= n; k++) { | |
if (cage[m][k] == 1) { | |
partW.push_back(Code[m][k]); | |
} | |
} | |
} | |
word.insert(word.begin(), partW); | |
partW.clear(); | |
} | |
for (auto l : word) { | |
std::cout << l; | |
} | |
std::cout << std::endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment