fork download
  1. #include<iostream>
  2. #include<cmath>
  3. #include<algorithm>
  4. #include<iomanip>
  5. #include<climits>
  6. #include<numeric>
  7. #include<set>
  8. #include<sstream>
  9. #include<map>
  10. #include<vector>
  11. #include<string>
  12. #include<regex>
  13.  
  14. using namespace std;
  15.  
  16. const long long MOD = (long long)(1e9 + 7);
  17.  
  18. vector<string> split(const string& haystack, const string& needle) {
  19. vector<string> result;
  20. size_t start_pos = 0;
  21. size_t found_pos = haystack.find(needle, start_pos);
  22. while (found_pos != string::npos) {
  23. size_t count = found_pos - start_pos;
  24. string token = haystack.substr(start_pos, count);
  25. if (!token.empty()) {
  26. result.push_back(token);
  27. }
  28. start_pos = found_pos + needle.length();
  29. found_pos = haystack.find(needle, start_pos);
  30. }
  31.  
  32. string last_token = haystack.substr(start_pos);
  33. if (!last_token.empty()) {
  34. result.push_back(last_token);
  35. }
  36. return result;
  37. }
  38.  
  39. int main() {
  40. map<string, int> mp;
  41. for (int i = 0;i < 10;i++) {
  42. string name;cin >> name;
  43. int mass;cin >> mass;
  44. mp[name] = mass;
  45. }
  46. regex pattern("([A-Z][a-z]*)(\\d*)");
  47. int t;cin >> t;
  48. for (int i = 1;i <= t;i++) {
  49. string s;cin >> s;
  50. long long sum = 0;
  51. for (sregex_iterator it(s.begin(), s.end(), pattern);it != sregex_iterator();it++) {
  52. string element = (*it)[1];
  53. string mass = (*it)[2];
  54. int count = (mass.empty()) ? 1 : stoi(mass);
  55. sum = sum + count * mp[element];
  56. }
  57. cout << sum << endl;
  58. }
  59. return 0;
  60. }
  61.  
  62.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
Standard output is empty