#define ALL(c) (c).begin(), (c).end()
class T9 {
public:
string message(vector <string> part, vector <string> dic, vector <string> keystr) {
string key;
for (int i = 0; i < keystr.size(); ++i) {
key += keystr[i];
}
key += '0';
vector<string> v;
{
string s;
for (int i = 0; i < key.size(); ++i) {
if (key[i] == '0') {
v.push_back(s);
v.push_back("0");
s = "";
} else s += key[i];
}
}
map<char, char> no;
for (int i = 0; i < part.size(); ++i) {
for (int j = 0; j < part[i].size(); ++j) {
no[part[i][j]] = i + '1';
}
}
map< string, vector<string> > D;
sort(ALL(dic));
for (int i = 0; i < dic.size(); ++i) {
string s;
for (int j = 0; j < dic[i].size(); ++j) {
s += no[dic[i][j]];
}
D[s].push_back(dic[i]);
}
string ret;
for (int i = 0; i < v.size(); ++i) {
int n = 0;
n += count(ALL(v[i]), '#');
n += count(ALL(v[i]), '*') * 5;
for (int j = 0; j < v[i].size(); ++j) {
if (v[i][j] == '#' || v[i][j] == '*' ) {
v[i].erase(v[i].begin() + j--);
}
}
if (v[i].empty()) continue;
if (v[i] != "0") ret += D[v[i]][n];
else ret += ' ';
}
ret.erase(ret.end() - 1);
return ret;
}
};
10/16/2011
SRM468 Div1 Easy
250
登録:
コメントの投稿
(
Atom
)
0 件のコメント :
コメントを投稿