-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
89 lines (87 loc) · 2.25 KB
/
main.c
1
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright Mantu Matei 312CA 2022-2023
#include <stdio.h>
#include <stdlib.h>
#include "matrix_operations.h"
#include "matrix_array.h"
#include "checks.h"
int main(void)
{
char c;
int ind, i, j, *m, *n, ***mats, size = 0, cap = 1, garbage, pow;
init(&mats, &m, &n);
scanf("%c ", &c);
while ('A' <= c && c <= 'Z') {
if (c == 'L') {
if (size == cap)
change_cap(&mats, &m, &n, &cap, 'I');
scanf("%d%d", &m[size], &n[size]);
load_matrix(&mats[size], m[size], n[size]);
read_matrix(mats[size], m[size], n[size]);
size++;
} else if (c == 'D') {
scanf("%d", &ind);
if (matrix_exists(ind, size))
printf("%d %d\n", m[ind], n[ind]);
} else if (c == 'P') {
scanf("%d", &ind);
if (matrix_exists(ind, size))
print_matrix(mats[ind], m[ind], n[ind]);
} else if (c == 'C') {
scanf("%d", &ind);
if (matrix_exists(ind, size))
crop_matrix(&mats[ind], &m[ind], &n[ind]);
} else if (c == 'M') {
scanf("%d%d", &i, &j);
if (check_M(i, j, size, n, m)) {
if (size == cap)
change_cap(&mats, &m, &n, &cap, 'I');
m[size] = m[i];
n[size] = n[j];
mats[size++] = mat_product(mats[i], mats[j], m[i], n[i], n[j]);
}
} else if (c == 'O') {
matrix_sort(mats, m, n, size);
} else if (c == 'T') {
scanf("%d", &ind);
if (matrix_exists(ind, size))
transpose_matrix(&mats[ind], &m[ind], &n[ind]);
} else if (c == 'R') {
scanf("%d%d", &ind, &pow);
if (check_R(ind, pow, m, n, size))
matrix_power(&mats[ind], n[ind], pow);
} else if (c == 'F') {
scanf("%d", &ind);
if (matrix_exists(ind, size)) {
free_matrix(mats[ind], m[ind]);
m[ind] = 0;
n[ind] = 0;
size--;
for (i = ind; i < size; ++i) {
mats[i] = mats[i + 1];
m[i] = m[i + 1];
n[i] = n[i + 1];
}
if (size * 2 < cap)
change_cap(&mats, &m, &n, &cap, 'D');
}
} else if (c == 'Q') {
free_matrices(mats, m, n, size);
return 0;
} else if (c == 'S') {
scanf("%d%d", &i, &j);
if (check_M(i, j, size, n, m)) {
if (size == cap)
change_cap(&mats, &m, &n, &cap, 'I');
m[size] = m[i];
n[size] = n[j];
mats[size++] = strassen(mats[i], mats[j], m[i]);
}
} else {
printf("Unrecognized command\n");
}
while (scanf("%d", &garbage))
;
scanf(" %c", &c);
}
return 0;
}