[프로그래머스] 대충 만든 자판
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int INF = 105;
vector<int> solution(vector<string> keymap, vector<string> targets) {
vector<int> alpha(27, INF);
for(int i = 0; i<keymap.size(); ++i){
for(int j = 0; j < keymap[i].length(); ++j){
int cur = keymap[i][j] - 'A';
alpha[cur] = min(alpha[cur], j + 1);
}
}
vector<int> answer;
for(int i = 0; i<targets.size(); ++i){
int ans = 0;
bool possible = true;
for(int j = 0; j<targets[i].length(); ++j){
int cur = targets[i][j] - 'A';
if(alpha[cur] == INF){
answer.push_back(-1);
possible = false;
break;
}
else ans += alpha[cur];
}
if(possible) answer.push_back(ans);
}
return answer;
}