-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy path1512B.cpp
More file actions
executable file
·52 lines (43 loc) · 964 Bytes
/
1512B.cpp
File metadata and controls
executable file
·52 lines (43 loc) · 964 Bytes
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
/*
Problem Code: 1512B
Time: O(n²)
Space: O(1)
Author: Mohammed Shoaib, github.com/Mohammed-Shoaib
*/
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;
void almost_rectangle(int n, vector<string>& grid) {
vector<pair<int, int>> pos;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (grid[i][j] == '*')
pos.push_back({i, j});
for (int i = 1; i >= 0; i--)
pos.push_back(pos[i]);
if (pos[0].first == pos[1].first)
pos[2].first = pos[3].first = (pos[0].first + 1) % n;
else if (pos[0].second == pos[1].second)
pos[2].second = pos[3].second = (pos[0].second + 1) % n;
else
swap(pos[0].second, pos[1].second);
for (auto& [x, y]: pos)
grid[x][y] = '*';
for (string& s: grid)
cout << s << endl;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> grid(n);
for (string& s: grid)
cin >> s;
almost_rectangle(n, grid);
}
return 0;
}