#include<iostream>
using namespace std;
int main(void) {
int n, k, r, s, c, ans = 0;
string t, y;
cin >> n >> k >> r >> s >> c >> t;
for (int i = 1; i <= n; i++) {
if (t[i - 1] == 'r') {
if (i - k - 1 >= 0) {
if (y[i - k - 1] != 'c') {
y[i - 1] = 'c';
ans += c;
// cout << "k" << ans << endl;
}
else {
y[i - 1] = 'c';
// cout << "k" << endl;
}
}
else {
y[i - 1] = 'c';
ans += c;
// cout << ans << endl;
}
}
else if (t[i - 1] == 's') {
if (i - k - 1 >= 0) {
if (y[i - k - 1] != 'r') {
y[i - 1] = 'r';
ans += r;
// cout << "k" << ans << endl;
}
else {
y[i - 1] = 's';
// cout << "k" << endl;
}
}
else {
y[i - 1] = 'r';
ans += r;
// cout << ans << endl;
}
}
else if (t[i - 1] == 'c') {
if (i - k - 1 >= 0) {
if (y[i - k - 1] != 's') {
y[i] = 's';
ans += s;
// cout << "k" << ans << endl;
}
else {
y[i - 1] = 'c';
// cout << "k" << endl;
}
}
else {
y[i - 1] = 's';
ans += s;
// cout << ans << endl;
}
}
}
cout << ans;
return 0;
}
题目:石头剪刀布 试卷:https://ks.wjx.top/vm/hxtCGep.aspx