• Source
    1. #include<stdio.h>
    2. #include<string>
    3. #include<map>
    4. #include<iostream>
    5.  
    6. using namespace std;
    7.  
    8. map<string,int>mp;
    9.  
    10. int main()
    11. {
    12. char str[20],ch;
    13. string s;
    14. long long m,n,i,a,sum;
    15. while(scanf("%lld%lld",&m,&n)==2)
    16. {
    17. for(i=1; i<=m; i++)
    18. {
    19. scanf("%s %lld",str,&a);
    20. mp[str]=a;
    21. }
    22.  
    23. sum=0;
    24.  
    25. s="";
    26.  
    27. getchar();
    28.  
    29. for(i=1; i<=n; i++)
    30. {
    31. for(;;)
    32. {
    33. scanf("%c",&ch);
    34.  
    35. if(ch!=' ' && ch!='\n')
    36. {
    37. s+=ch;
    38. }
    39.  
    40. else if(ch==' '||ch=='\n')
    41. {
    42. if(mp.find(s)!=mp.end())
    43. {
    44. sum+=mp[s];
    45. }
    46. s="";
    47. }
    48.  
    49. if(ch=='.')
    50. {
    51. printf("%lld\n",sum);
    52. sum=0;
    53. break;
    54. }
    55. }
    56. }
    57. mp.clear();
    58. }
    59. return 0;
    60. }
    61.