-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11360 - Have Fun with Matrices.cpp
203 lines (179 loc) · 2.83 KB
/
11360 - Have Fun with Matrices.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*input
2
4
1234
5678
1234
5678
1
transpose
3
120
129
120
1
col 1 2
*/
#include <stdio.h>
#include <cmath>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string.h>
#include <stack>
#include <map>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
#define r(input) freopen("input.txt","r",stdin)
#define w(output) freopen("output.txt","w",stdout)
#define FOR(i, a) for ( int i = 0 ; i < a ; i++ )
#define FOREACH(l) for (auto it = l.begin(); it != l.end(); it++)
#define BitCount(i) __builtin_popcount(i)
#define Sort(v) sort(v.begin(),v.end())
#define cover(a, d) memset(a,d,sizeof(a))
#define remove(v,e) v.erase(std::find(v.begin(),v.end(),e))
#define is_in(container, element) (container.find(element) != container.end())
#define sz size
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define VISITED 1
#define UNVISITED 0
#define INF 1000000000
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef pair<int,ii> triple;
inline int toint(string s){ll v; istringstream sin(s);sin>>v;return v;}
inline ll toll(string s){ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline char toString(T x) { ostringstream sout; sout << x; return sout.str()[0];}
class Compare
{
public:
bool operator() (ii t1 , ii t2){
return t1>t2;
}
};
vector<string> mat;
int n;
void inc()
{
FOR(i , n)
{
FOR(j , n)
{
char tmp = mat[i][j];
if(tmp == '9') tmp = '0';
else tmp++;
mat[i][j] = toString(tmp);
}
}
}
void dec()
{
FOR(i , n)
{
FOR(j , n)
{
char tmp = mat[i][j];
if(tmp == '0') tmp = '9';
else tmp--;
mat[i][j] = toString(tmp);
}
}
}
void row(int a, int b)
{
a--;b--;
string tmp = mat[a];
mat[a] = mat[b];
mat[b] = tmp;
}
void col(int a, int b)
{
a--;b--;
FOR(i , n)
{
char tmp = mat[i][a];
mat[i][a] = mat[i][b];
mat[i][b] = tmp;
}
}
void trans()
{
bool t[20][20] = {0};
FOR(i , n)
{
FOR(j , n)
{
if(i == j) {t[i][j] = true;continue;}
if(!t[i][j])
{
char tmp = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = tmp;
}
t[i][j] = true;
t[j][i] = true;
}
}
}
int main()
{
int t;
cin >> t;
FOR(c, t)
{
cin >> n;
mat.clear();
FOR(i , n)
{
string tmp;
cin >> tmp;
mat.pb(tmp);
}
int m;
cin >> m;
FOR(i , m)
{
string order;
cin >> order;
if(order == "transpose")
{
trans();
}
else if(order == "row")
{
int a , b;
cin >> a >> b;
row(a, b);
}
else if(order == "col")
{
int a , b;
cin >> a >> b;
col(a,b);
}
else if(order == "inc")
{
inc();
}
else
{
dec();
}
}
cout <<"Case #"<< (c+1)<< endl;
FOR(i , n)
cout << mat[i] << endl;
cout << endl;
}
}