forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprva.cpp
63 lines (53 loc) · 1.19 KB
/
prva.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
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
vector<vector<char>> v;
v.resize(m, vector<char>(n));
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
cin >> v[i][j];
}
}
vector<string> words;
string word = "";
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
if(v[i][j] == '#') {
words.push_back(word);
word = "";
}
else {
word.push_back(v[i][j]);
}
}
words.push_back(word);
word = "";
}
word = "";
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(v[j][i] == '#') {
words.push_back(word);
word = "";
}
else {
word.push_back(v[j][i]);
}
}
words.push_back(word);
word = "";
}
vector<string> ok;
for(auto a : words) {
if(a.length() > 1) {
ok.push_back(a);
}
}
sort(ok.begin(), ok.end());
cout << ok[0] << endl;
}