forked from Diusrex/UVA-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10393 The One-Handed Typist.cpp
83 lines (65 loc) · 2.09 KB
/
10393 The One-Handed Typist.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
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
bool fingerAvailable[15];
int fingerRequired[128];
void SetUp()
{
fingerRequired['q'] = fingerRequired['a'] = fingerRequired['z'] = 1;
fingerRequired['w'] = fingerRequired['s'] = fingerRequired['x'] = 2;
fingerRequired['e'] = fingerRequired['d'] = fingerRequired['c'] = 3;
fingerRequired['r'] = fingerRequired['f'] = fingerRequired['v'] =
fingerRequired['t'] = fingerRequired['g'] = fingerRequired['b'] = 4;
fingerRequired['y'] = fingerRequired['h'] = fingerRequired['n'] =
fingerRequired['u'] = fingerRequired['j'] = fingerRequired['m'] = 7;
fingerRequired['i'] = fingerRequired['k'] = 8;
fingerRequired['o'] = fingerRequired['l'] = 9;
fingerRequired['p'] = 10;
}
bool Possible(const string &str)
{
for (string::const_iterator iter = str.begin(); iter != str.end(); ++iter)
{
if (!fingerAvailable[fingerRequired[*iter]])
return false;
}
return true;
}
int main()
{
SetUp();
int F, N;
while (cin >> F >> N)
{
for (int i = 1; i <= 10; ++i)
fingerAvailable[i] = true;
while (F--)
{
int cF;
cin >> cF;
fingerAvailable[cF] = false;
}
int bestLength = 0;
set<string> longestWords;
string current;
while (N--)
{
cin >> current;
if (current.size() > bestLength && Possible(current))
{
bestLength = current.size();
longestWords.clear();
longestWords.insert(current);
}
else if (current.size() == bestLength && Possible(current))
longestWords.insert(current);
}
vector<string> best(longestWords.begin(), longestWords.end());
sort(best.begin(), best.end());
cout << best.size() << '\n';
for (int i = 0; i < best.size(); ++i)
cout << best[i] << '\n';
}
}