-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathletter.cpp
More file actions
107 lines (100 loc) · 1.96 KB
/
letter.cpp
File metadata and controls
107 lines (100 loc) · 1.96 KB
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
/*A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with n rows and m columns.
Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland.
Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices,
he wants to send his creation, but to spend as little money as possible.
For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles.
Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares.
The rectangle's sides should be parallel to the sheet's sides.*/
#include<iostream>
using namespace std;
int main()
{
int nr, mc;
cin >> nr >> mc;
char** arr = new char* [nr];
for (int i = 0; i < nr; ++i)
arr[i] = new char[mc];
int check = 0;
for (int i = 0; i < nr; i++)
{
for (int j = 0; j < mc; j++)
cin >> arr[i][j];
}
int up = -1;
int down = -1;
int right = -1;
int left = -1;
int flag = 0;
//up side
for (int i = 0; i < nr; i++)
{
for (int j = 0; j < mc; j++)
{
if (arr[i][j] == '*')
{
up = i;
flag = 1;
break;
}
}
if (flag == 1)
break;
}
//down side
flag = 0;
for (int i = nr - 1; i >= 0; i--)
{
for (int j = 0; j < mc; j++)
{
if (arr[i][j] == '*')
{
down = i;
flag = 1;
break;
}
}
if (flag == 1)
break;
}
//left side
flag = 0;
for (int i = 0; i < mc; i++)
{
for (int j = 0; j < nr; j++)
{
if (arr[j][i] == '*')
{
left = i;
flag = 1;
break;
}
}
if (flag == 1)
break;
}
//right side
flag = 0;
for (int i = mc-1; i >= 0; i--)
{
for (int j = 0; j < nr; j++)
{
if (arr[j][i] == '*')
{
right = i;
flag = 1;
break;
}
}
if (flag == 1)
break;
}
for (int i = up; i <= down; i++)
{
for (int j = left; j <= right; j++)
{
cout << arr[i][j];
}
cout << endl;
}
return 0;
}