-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicreorder.cpp
74 lines (60 loc) · 1.76 KB
/
basicreorder.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
#include <algorithm>
#include <iostream>
#include <fstream>
#include <map>
#include <string>
#include <vector>
using namespace std;
bool freqcompare(pair<char, long long> f, pair<char, long long> s) { return f.second > s.second; }
string alphabet = "abcdefghijklmnopqrstuvwxyz";
int main(int argc, char** argv)
{
int tmp;
ifstream win("words/wordlist");
win >> tmp;
string word;
win >> word; // Eat the rest of the header
map<char,long long> freq;
for (string::iterator c = alphabet.begin();
c != alphabet.end();
++c)
freq[*c] = 0;
long long count;
while (win >> count) {
win >> word;
for (string::iterator i = word.begin(); i != word.end(); ++i)
freq[*i] += count;
}
vector<string> keys;
keys.push_back("abc");
keys.push_back("def");
keys.push_back("ghi");
keys.push_back("jkl");
keys.push_back("mno");
keys.push_back("pqrs");
keys.push_back("tuv");
keys.push_back("wxyz");
count = 0;
int key = 2;
for (vector<string>::iterator s = keys.begin();
s != keys.end();
++s, ++key) {
cout << key << "\\to [";
vector<pair<char,long long> > ordered;
for (string::iterator c = s->begin();
c != s->end();
++c)
ordered.push_back(pair<char,long long>(*c, freq[*c]));
sort(ordered.begin(), ordered.end(), freqcompare);
int j = 1;
for (vector<pair<char,long long> >::iterator i = ordered.begin();
i != ordered.end();
i++, j++) {
cout << i->first;
count += j*(i->second);
}
cout << "]," << endl;
}
cout << count << " button presses" << endl;
return 0;
}