-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmediateDecodability_UVA644.cpp
76 lines (64 loc) · 1.58 KB
/
immediateDecodability_UVA644.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("immediateDecodability_UVA644.in");
ofstream fout("immediateDecodability_UVA644.out");
int main()
{
int T = 1;
vector<string> a;
while (true)
{
string in = "-";
fin >> in;
if (in == "-")
{
break;
}
else if (in == "9")
{
sort(a.begin(), a.end());
bool flag = true;
int size0 = a.size();
map<string, bool> _map;
for (int i = 0; i <= size0 - 1 && flag == true; ++i)
{
int size1 = a[i].size();
string temp = "";
for (int j = 0; j <= size1 - 1 && flag == true; ++j)
{
temp += a[i][j];
if (_map[temp] == true)
{
flag = false;
}
}
_map[a[i]] = true;
}
if (flag == true)
{
fout << "Set " << T << " is immediately decodable\n";
}
else
{
fout << "Set " << T << " is not immediately decodable\n";
}
++T;
a.clear();
}
else
{
a.push_back(in);
}
}
return 0;
}