1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #include <iostream>
- #include <map>
- using namespace std;
- map<char, int> init() {
- map<char, int> defineKey;
- char key = 'A';
- for (int i = 0; i < 26; i++) {
- defineKey.insert(make_pair(key, i + 1));
- key += 1;
- }
- return defineKey;
- }
- int main() {
- map<char, int> mpKey = init();
- char keys[256] = {'\0'};
- while (cin.getline(keys, 256)) {
- if (keys[0] == '#') {
- break;
- }
- int val = 0;
- int result = 0;
- for (int i = 0; keys[i] != '\0'; i++) {
- if (keys[i] < 'A' || keys[i] > 'Z') {
- continue;
- }
- map<char, int>::iterator iter = mpKey.find(keys[i]);
- if (iter != mpKey.end()) {
- val = iter->second;
- }
- // cout << "val - " << val << endl;
- result += ((i+1)*val);
- }
- cout << result << endl;
- memset(keys, 0, 256);
- }
- return 0;
- }
|