main.cpp 954 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <iostream>
  2. #include <map>
  3. using namespace std;
  4. map<char, int> init() {
  5. map<char, int> defineKey;
  6. char key = 'A';
  7. for (int i = 0; i < 26; i++) {
  8. defineKey.insert(make_pair(key, i + 1));
  9. key += 1;
  10. }
  11. return defineKey;
  12. }
  13. int main() {
  14. map<char, int> mpKey = init();
  15. char keys[256] = {'\0'};
  16. while (cin.getline(keys, 256)) {
  17. if (keys[0] == '#') {
  18. break;
  19. }
  20. int val = 0;
  21. int result = 0;
  22. for (int i = 0; keys[i] != '\0'; i++) {
  23. if (keys[i] < 'A' || keys[i] > 'Z') {
  24. continue;
  25. }
  26. map<char, int>::iterator iter = mpKey.find(keys[i]);
  27. if (iter != mpKey.end()) {
  28. val = iter->second;
  29. }
  30. // cout << "val - " << val << endl;
  31. result += ((i+1)*val);
  32. }
  33. cout << result << endl;
  34. memset(keys, 0, 256);
  35. }
  36. return 0;
  37. }