# ZeroJudge - a869: 9. Letter Scramble ### 題目連結:https://zerojudge.tw/ShowProblem?problemid=a869 ###### tags: `ZeroJudge` `模擬` ```cpp= #include <iostream> #include <string> using namespace std; int points[128] = {}; void Initialize() { points['A'] = points['E'] = points['I'] = points['L'] = points['N'] = points['O'] = points['R'] = points['S'] = points['T'] = points['U'] = 1; points['D'] = points['G'] = 2; points['B'] = points['C'] = points['M'] = points['P'] = 3; points['F'] = points['H'] = points['V'] = points['W'] = points['Y'] = 4; points['K'] = 5; points['J'] = points['X'] = 8; points['Q'] = points['Z'] = 10; } int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int gridSize, wordAmount, score, wordBonus, letterBonus, nowX, nowY, dx, dy; string grid[10][10], word; char placement; Initialize(); while (cin >> gridSize) { for (int i = 1; i <= gridSize; ++i) for (int j = 1; j <= gridSize; ++j) cin >> grid[i][j]; cin >> wordAmount; while (wordAmount--) { cin >> word >> nowY >> nowX >> placement; (placement == 'H' ? (dx = 1, dy = 0) : (dx = 0, dy = 1)); wordBonus = 1; score = 0; for (int i = 0; i != word.size(); ++i) { letterBonus = (grid[nowY][nowX][1] == 'L' ? grid[nowY][nowX][0] - '0' : 1); wordBonus *= (grid[nowY][nowX][1] == 'W' ? grid[nowY][nowX][0] - '0' : 1); score += points[word[i]] * letterBonus; nowX += dx; nowY += dy; } cout << word << ' ' << score * wordBonus << '\n'; } } } ```