50173. Matrix Operations
難度:3/51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#include <stdio.h>
#include <stdint.h>
#include "matrixOperations.h"
int get_bit(uint64_t *n, int x, int y){
return ((*n) >> (8 * x + y)) & 1;
}
void set_bit(uint64_t *n, int x, int y){
(*n) |= ((uint64_t)1 << ((8 * x + y)));
}
void printMatrix(uint64_t *m){
printf("%llu\n", *m);
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
printf("%d", get_bit(m, i, j));
}
puts("");
}
}
void rotateMatrix(uint64_t *m){
uint64_t temp = 0;
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
int b = get_bit(m, i, j);
if(b) set_bit(&temp, j, 7 - i);
}
}
(*m) = temp;
}
void transposeMatrix(uint64_t *m){
uint64_t temp = 0;
for(int i = 0; i < 8; i++){
for(int j = 0; j < 8; j++){
int b = get_bit(m, i, j);
if(b) set_bit(&temp, j, i);
}
}
(*m) = temp;
}