fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. void wypisz_macierz(vector<vector<char>>& macierz, int N) {
  6. for(int i = 0; i < N; i++) {
  7. for(int j = 0; j < N; j++) {
  8. cout << macierz[i][j];
  9. }
  10. cout << endl;
  11. }
  12. }
  13.  
  14. void obrot_w_prawo_270(vector<vector<char>>& matrix, int N) {
  15. //int temp[N][N];
  16. vector<vector<char>> temp(N, vector<char>(N, 0));
  17. for(int i = 0; i < N; i++) {
  18. for(int j = 0; j < N; j++) {
  19. temp[N-j-1][i] = matrix[i][j];
  20. }
  21. }
  22. for(int i = 0; i < N; i++) {
  23. for(int j = 0; j < N; j++) {
  24. matrix[i][j] = temp[i][j];
  25. }
  26. }
  27. }
  28.  
  29. void obrot_w_lewo_270(vector<vector<char>>& matrix, int N) {
  30. vector<vector<char>> temp(N, vector<char>(N, 0));
  31. for(int i = 0; i < N; i++) {
  32. for(int j = 0; j < N; j++) {
  33. temp[j][N-i-1] = matrix[i][j];
  34. }
  35. }
  36. for(int i = 0; i < N; i++) {
  37. for(int j = 0; j < N; j++) {
  38. matrix[i][j] = temp[i][j];
  39. }
  40. }
  41. }
  42. void obracanieMacierzy(int n, char** macierz) {
  43. for (int i = 0; i < n / 2; i++) {
  44. for (int j = 0; j < n; j++) {
  45. int temp = macierz[i][j];
  46. macierz[i][j] = macierz[n - i - 1][n - j - 1];
  47. macierz[n - i - 1][n - j - 1] = temp;
  48. }
  49. }
  50. if (n % 2 != 0) {
  51. for (int j = 0; j < n / 2; j++) {
  52. int temp = macierz[n / 2][j];
  53. macierz[n / 2][j] = macierz[n / 2][n - j - 1];
  54. macierz[n / 2][n - j - 1] = temp;
  55. }
  56. }
  57. }
  58. void rotate180(vector<vector<char>>& matrix, int N) {
  59. for (int i = 0; i < N/2; i++) {
  60. for (int j = 0; j < N; j++) {
  61. swap(matrix[i][j], matrix[N-i-1][N-j-1]);
  62. }
  63. }
  64. if (N%2 == 1) {
  65. int mid = N/2;
  66. for (int j = 0; j < mid; j++) {
  67. swap(matrix[mid][j], matrix[mid][N-j-1]);
  68. }
  69. }
  70. }
  71.  
  72. // Funkcja obraca macierz o 180 stopni w lewo
  73. void rotate180_left(vector<vector<char>>& matrix,int N) {
  74. for (int i = 0; i < N/2; i++) {
  75. for (int j = 0; j < N; j++) {
  76. swap(matrix[i][j], matrix[N-i-1][N-j-1]);
  77. }
  78. }
  79. for (int i = 0; i < N; i++) {
  80. for (int j = 0; j < N/2; j++) {
  81. swap(matrix[i][j], matrix[i][N-j-1]);
  82. }
  83. }
  84. for (int i = 0; i < N/2; i++) {
  85. for (int j = i+1; j < N; j++) {
  86. swap(matrix[i][j], matrix[j][i]);
  87. }
  88. }
  89. }
  90.  
  91. // Funkcja wykonuje transpozycjê macierzy wzglêdem g³ównej przek¹tnej
  92. void transpose_main(vector<vector<char>>& matrix,int N) {
  93.  
  94. for (int i = 0; i < N; i++) {
  95. for (int j = i+1; j < N; j++) {
  96. swap(matrix[i][j], matrix[j][i]);
  97. }
  98. }
  99. }
  100.  
  101. // Funkcja wykonuje transpozycjê macierzy wzglêdem drugiej przek¹tnej
  102. void transpose_secondary(vector<vector<char>>& matrix,int N) {
  103. vector<vector<char>> temp(N, vector<char>(N));
  104. for(int i = 0;i < N;i++){
  105. for (int j = 0; j < N; j++) {
  106. // cout<<N-j-1<<" "<<N-i-1<<endl;
  107. temp[N-j-1][N-i-1]=matrix[i][j];
  108. }
  109. }
  110. matrix=temp;
  111. }
  112.  
  113. // funkcja do odbicia poziomego macierzy
  114. void flipVertical(vector<vector<char>>& matrix,int N) {
  115.  
  116. for (int i = 0; i < N/2; i++) {
  117. for (int j = 0; j < N; j++) {
  118. swap(matrix[i][j], matrix[N-i-1][j]);
  119. }
  120. }
  121. }
  122.  
  123. // funkcja do odbicia pionowego macierzy
  124. void flipHorizontal(vector<vector<char>>& matrix,int N) {
  125.  
  126. for (int i = 0; i < N; i++) {
  127. for (int j = 0; j < N/2; j++) {
  128. swap(matrix[i][j], matrix[i][N-j-1]);
  129. }
  130. }
  131. }
  132. void rotateRight(vector<vector<char>>& matrix, int N) {
  133. // utworzenie nowej macierzy z obróconymi elementami
  134. vector<vector<char>> rotatedMatrix(N, vector<char>(N));
  135. for (int i = 0; i < N; i++) {
  136. for (int j = 0; j < N; j++) {
  137. rotatedMatrix[i][j] = matrix[N - j - 1][i];
  138. }
  139. }
  140. // przypisanie nowej macierzy do oryginalnej
  141. matrix = rotatedMatrix;
  142. }
  143.  
  144. void rotateLeft(vector<vector<char>>& matrix, int N) {
  145. // utworzenie nowej macierzy z obróconymi elementami
  146. vector<vector<char>> rotatedMatrix(N, vector<char>(N));
  147. for (int i = 0; i < N; i++) {
  148. for (int j = 0; j < N; j++) {
  149. rotatedMatrix[i][j] = matrix[j][N - i - 1];
  150. }
  151. }
  152. // przypisanie nowej macierzy do oryginalnej
  153. matrix = rotatedMatrix;
  154. }
  155.  
  156. void transpose(vector<vector<char>>& matrix, int N) {
  157. // zamiana elementów macierzy wzglêdem g³ównej przek¹tnej
  158. for (int i = 0; i < N; i++) {
  159. for (int j = i + 1; j < N; j++) {
  160. int temp = matrix[i][j];
  161. matrix[i][j] = matrix[j][i];
  162. matrix[j][i] = temp;
  163. }
  164. }
  165. }
  166. void analiza(string str,vector<vector<char>>& matrix, int N)
  167. {
  168. int dl=str.length(),i=0,obrot=0;
  169. //for(i=0;i<dl-1;i++)
  170. while(i<dl-1)
  171. {
  172. //cout<<"jestem"<<endl;
  173. while(str[i]=='A'||str[i]=='B'||str[i]=='C'||str[i]=='X'||str[i]=='Y'||str[i]=='Z')
  174. {
  175. switch (str[i])
  176. {
  177. case 'A':obrot+=90 ;
  178. break;
  179. case 'B':obrot+=180;
  180. break;
  181. case 'C':obrot+=270;
  182. break;
  183. case 'X':obrot+=-90;
  184. break;
  185. case 'Y':obrot+=-180;
  186. break;
  187. case 'Z':obrot+=-270;
  188. break;
  189. }
  190. i++;
  191. }
  192.  
  193. obrot=obrot%360;
  194. cout<<obrot<<endl;
  195.  
  196. switch(obrot)
  197. {
  198. case 90:rotateRight(matrix,N) ;
  199. break;
  200. case 180:rotate180(matrix,N);
  201. break;
  202. case 270:obrot_w_prawo_270(matrix,N);
  203. break;
  204. case -90:rotateLeft(matrix,N);
  205. break;
  206. case -180:rotate180(matrix,N);
  207. break;
  208. case -270:obrot_w_lewo_270(matrix,N);
  209. }
  210. obrot=0;
  211. while(i<dl-1 && str[i]==str[i+1])i=i+2;
  212. //cout<<i<<endl;
  213. if(i<dl-1 && (str[i]=='T'||str[i]=='D'||str[i]=='H'||str[i]=='V'))
  214. {
  215. //cout<<"tu"<<endl;
  216. switch(str[i])
  217. {
  218. case 'T':transpose_main(matrix,N);
  219. break;
  220. case 'D':transpose_secondary( matrix,N);
  221. break;
  222. case 'H':flipHorizontal(matrix,N);
  223. break;
  224. case 'V':flipVertical(matrix,N);
  225. break;
  226.  
  227. }
  228. cout<<"wyk="<<str[i]<<endl;
  229. i++;
  230. }
  231. }
  232. }
  233. void analize(string str,vector<vector<char>>& matrix, int N)
  234. {
  235. int dl=str.length(),i;
  236. cout<<"dl="<<dl<<endl;
  237. for(i=0;i<dl-1;i++)
  238. {
  239. switch(str[i])
  240. {
  241. case 'A':rotateRight(matrix,N) ;
  242. //cout<<"A"<<endl;
  243. break;
  244. case 'B':rotate180(matrix,N);
  245. //cout<<"B"<<endl;
  246. //wypisz_macierz(matrix,N);
  247. break;
  248. case 'C':obrot_w_prawo_270(matrix,N);
  249. //cout<<"C"<<endl;
  250. break;
  251. case 'X':rotateLeft(matrix,N);
  252. //cout<<"X"<<endl;
  253. break;
  254. case 'Y':rotate180(matrix,N);
  255. //cout<<"Y"<<endl;
  256. break;
  257. case 'Z':obrot_w_lewo_270(matrix,N);
  258. //cout<<"Z"<<endl;
  259. break;
  260. case 'T':transpose_main(matrix,N);
  261. // cout<<"T"<<endl;
  262. break;
  263. case 'D':transpose_secondary( matrix,N);
  264. //cout<<"D"<<endl;
  265. break;
  266. case 'H':flipHorizontal(matrix,N);
  267. //cout<<"H"<<endl;
  268. break;
  269. case 'V':flipVertical(matrix,N);
  270. //cout<<"V"<<endl;
  271. break;
  272. case '&':
  273. //cout<<"&"<<endl;
  274. break;
  275. }
  276.  
  277. }
  278. cout<<i<<endl;
  279. }
  280. int main() {
  281. ios_base::sync_with_stdio(false);
  282. int N,t,dl,obrot=0;
  283. string str;
  284. cin>>t;
  285.  
  286. while(t--)
  287. {
  288. cin >> N;
  289. //cout<<N<<endl;
  290. // wczytanie macierzy
  291. vector<vector<char>> matrix(N, vector<char>(N));
  292. //cout<<matrix.size()<<endl;
  293. //vector<vector<char>> matrix2(N, vector<char>(N));
  294. for (int i = 0; i < N; i++) {
  295. for (int j = 0; j < N; j++) {
  296. cin >> matrix[i][j];
  297. }
  298. }
  299. // matrix2=matrix;
  300. cin>>str;
  301. cout<<str<<endl;
  302. analiza(str,matrix,N);
  303. //cout<<"po:"<<endl;
  304. wypisz_macierz(matrix,N);
  305. cout<<endl;
  306.  
  307. }
  308. return 0;
  309. }
  310.  
  311. // transpozycja wzglêdem g³ównej przek¹t
  312.  
Success #stdin #stdout 0.01s 5548KB
stdin
10
6
qldswt
mhmjxq
edqkpr
ngprox
vfpeua
gbsxex
YYTATT&
6
qldswt
mhmjxq
edqkpr
ngprox
vfpeua
gbsxex
H&
6
qrjaty
dimofu
gclqur
clqecd
rhvqsu
wbvntm
DVZYXBCXXY&

6
qrjaty
dimofu
gclqur
clqecd
rhvqsu
wbvntm
Z&


4
abcf
defg
ghih
lkjh
ABTHVDTHDACVDT&
4
abcf
defg
ghih
lkjh
HBH&
4
abcf
defg
ghih
lkjh
C&
4
abcf
defg
ghih
lkjh
T&
4
abcf
defg
ghih
lkjh
D&
4
abcf
defg
ghih
lkjh
H&
4
abcf
defg
ghih
lkjh
V&
4
abcf
defg
ghih
lkjh
X&
4
abcf
defg
ghih
lkjh
Y&
4
abcf
defg
ghih
lkjh
Z&
5
poiud
sdfgk
dfsad
dfghj
qwert
X&
3
4
abcf
defg
ghih
lkjh
TDHVVHDT&
4
cGhJ
EEEE
aAaA
xYzY
HVX&
5
poiud
sdfgk
dfsad
dfghj
qwert
TDHVVHDT&
stdout
YYTATT&
0
wyk=T
90
twsdlq
qxjmhm
rpkqde
xorpgn
auepfv
xexsbg

H&
0
wyk=H
twsdlq
qxjmhm
rpkqde
xorpgn
auepfv
xexsbg

DVZYXBCXXY&
0
wyk=D
0
wyk=V
-90
qrjaty
dimofu
gclqur
clqecd
rhvqsu
wbvntm

Z&
-270
wrcgdq
bhlcir
vvqlmj
nqeqoa
tscuft
mudruy

ABTHVDTHDACVDT&
270
wyk=T
0
wyk=H
0
wyk=V
0
wyk=D
0
wyk=T
0
wyk=H
0
wyk=D
0
wyk=V
0
wyk=D
0
wyk=T
fghh
cfij
behk
adgl

HBH&
0
wyk=H
180
wyk=H
hjkl
hihg
gfed
fcba

C&
270
fghh
cfij
behk
adgl

T&
0
wyk=T
adgl
behk
cfij
fghh

D&
0
wyk=D
hhgf
jifc
kheb
lgda

H&
0
wyk=H
fcba
gfed
hihg
hjkl