http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2205
#include <iostream> #include <vector> using namespace std; int main (int argc, const char * argv[]) { int n; while (cin >> n) { if (n == 0) { //終了 break; } vector<string> tousen; vector<int> sho; vector<string> have_s; int sum = 0; int m; //入力 cin >> m; for (int i=0; i < n; i++) { string tmp_s; cin >> tmp_s; tousen.push_back(tmp_s); int tmp_i; cin >> tmp_i; sho.push_back(tmp_i); } for (int i=0; i < m; i++) { string tmp_s; cin >> tmp_s; have_s.push_back(tmp_s); } //計算 for (int i= 0; i < have_s.size(); i++) { for (int j=0; j < tousen.size(); j++) { bool tousen_flag = true; for (int k= 0; k < 8; k++) { if (tousen[j][k] != '*') { if (tousen[j][k] != have_s[i][k]) { tousen_flag = false; } } } if (tousen_flag) { sum += sho[j]; } } } //出力 cout << sum << endl; } return 0; }