Language: C++

#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

#define N_MAX 100

int n,m;
string NUM[N_MAX];
long R[N_MAX];

string S;
int t,k;


bool is_atari(string s1,string s2){
    for(int i = 0;i < 8;i++){
        if(s1[i] != '*'){
            if(s1[i] != s2[i])return false;
        }
    }
    return true;
}

/*
int getlen(string str){
    int i=0;
    int k=0;
    while(str[k] == '*' && str[k] != '\0')k++;
    while(str[k] != '\0'){
        k++;
        i++;
    }
    return i;
}*/



int main()
{
    long reward;
    string tmp;
    while(cin >> n >> m){
        if(n == 0)break;
        
        REP(n){
            cin >> S >> t;
            NUM[i] = S;
            R[i] = t;
        }

        reward = 0;
        REP(m){
            cin >> S;
            
            rep(j,n){
                if(is_atari(NUM[j],S)){
                    reward += R[j];
                    break;
                }
            }
        }
        cout << reward << endl;

    }      

    return 0;
}

Compiler output:
a.cc:14:1: error: 'string' does not name a type; did you mean 'stdin'?
   14 | string NUM[N_MAX];
      | ^~~~~~
      | stdin
a.cc:17:1: error: 'string' does not name a type; did you mean 'stdin'?
   17 | string S;
      | ^~~~~~
      | stdin
a.cc:21:15: error: 'string' was not declared in this scope
   21 | bool is_atari(string s1,string s2){
      |               ^~~~~~
a.cc:6:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
    5 | #include<map>
  +++ |+#include <string>
    6 | using namespace std;
a.cc:21:25: error: 'string' was not declared in this scope
   21 | bool is_atari(string s1,string s2){
      |                         ^~~~~~
a.cc:21:25: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
a.cc:21:34: error: expression list treated as compound expression in initializer [-fpermissive]
   21 | bool is_atari(string s1,string s2){
      |                                  ^
a.cc: In function 'int main()':
a.cc:47:5: error: 'string' was not declared in this scope
   47 |     string tmp;
      |     ^~~~~~
a.cc:47:5: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
a.cc:48:11: error: 'cin' was not declared in this scope
   48 |     while(cin >> n >> m){
      |           ^~~
a.cc:6:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #include<map>
  +++ |+#include <iostream>
    6 | using namespace std;
a.cc:52:20: error: 'S' was not declared in this scope
   52 |             cin >> S >> t;
      |                    ^
a.cc:53:13: error: 'NUM' was not declared in this scope
   53 |             NUM[i] = S;
      |             ^~~
a.cc:59:20: error: 'S' was not declared in this scope
   59 |             cin >> S;
      |                    ^
a.cc:62:29: error: 'NUM' was not declared in this scope
   62 |                 if(is_atari(NUM[j],S)){
      |                             ^~~
a.cc:62:28: error: 'is_atari' cannot be used as a function
   62 |                 if(is_atari(NUM[j],S)){
      |                    ~~~~~~~~^~~~~~~~~~
a.cc:68:9: error: 'cout' was not declared in this scope
   68 |         cout << reward << endl;
      |         ^~~~
a.cc:68:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:68:27: error: 'endl' was not declared in this scope
   68 |         cout << reward << endl;
      |                           ^~~~
a.cc:6:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    5 | #include<map>
  +++ |+#include <ostream>
    6 | using namespace std;