-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathBCFIBO-src.cpp
54 lines (51 loc) · 945 Bytes
/
BCFIBO-src.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
#include <iostream>
#include <string>
using namespace std;
long r, c;
string s[21];
long doc[21][21], ngang[21][21];
string res = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
long timdoc(long x, long y)
{
doc[x][y] = 0;
string ss = "";
while ((x < r) && s[x][y] != '#')
{
ss += s[x][y];
doc[x][y] = 0;
x++;
}
if (ss.length() < 2) return 0;
if (ss < res) res = ss;
}
long timngang(long x, long y)
{
ngang[x][y] = 0;
string ss = "";
while ((y < c) && (s[x][y] != '#'))
{
ss += s[x][y];
ngang[x][y] = 0;
y++;
}
if (ss.length() < 2) return 0;
if (ss < res) res = ss;
}
main()
{
cin >> r >> c;
for (long i = 0; i < r; i++) cin >> s[i];
for (long i = 0; i < r; i++)
for (long j = 0; j < c; j++)
{
doc[i][j] = 1;
ngang[i][j] = 1;
}
for (long i = 0; i < r; i++)
for (long j = 0; j < c; j++)
{
if (doc[i][j]) timdoc(i, j);
if (ngang[i][j]) timngang(i, j);
}
cout << res;
}