forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10132.cpp
114 lines (109 loc) · 1.82 KB
/
10132.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
#include <bits/stdc++.h>
using namespace std;
vector<string> files, sshort, slong;
string temp;
bool check();
int main()
{
bool first = true;
int N;
scanf("%d", &N);
scanf("\n");
for (int i = 0; i < N; i++)
{
files.clear();
sshort.clear();
slong.clear();
while (true)
{
if (!getline(cin, temp, '\n'))
{
break;
}
if (temp == "")
{
break;
}
files.push_back(temp);
}
int min = 1000, max = 0;
for (int j = 0; j < files.size(); j++)
{
if (files[j].size() < min)
{
min = files[j].size();
}
if (files[j].size() > max)
{
max = files[j].size();
}
}
for (int j = 0; j < files.size(); j++)
{
if (files[j].size() == min)
{
bool exist = false;
for (int k = 0; k < sshort.size(); k++)
if (files[j] == sshort[k])
{
exist = true;
}
if (!exist)
{
sshort.push_back(files[j]);
}
}
if (files[j].size() == max)
{
bool exist = false;
for (int k = 0; k < slong.size(); k++)
if (files[j] == slong[k])
{
exist = true;
}
if (!exist)
{
slong.push_back(files[j]);
}
}
}
bool found = false;
for (int j = 0; !found && j < sshort.size(); j++)
for (int k = 0; !found && k < slong.size(); k++)
{
temp = sshort[j] + slong[k];
found = check();
}
for (int j = 0; !found && j < sshort.size(); j++)
for (int k = 0; !found && k < slong.size(); k++)
{
temp = slong[k] + sshort[j];
found = check();
}
if (first)
{
first = false;
}
else
{
putchar(10);
}
cout << temp << endl;
}
return 0;
}
bool check()
{
int loc1, loc2;
int len = temp.size();
for (int i = 0; i < files.size(); i++)
{
loc1 = temp.find(files[i]);
loc2 = temp.rfind(files[i]);
if (loc1 != 0 && loc2 != len - files[i].size())
{
return false;
}
}
return true;
}