求查错
  • 板块灌水区
  • 楼主LGZX
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/25 20:42
  • 上次更新2024/7/25 21:45:23
查看原帖
求查错
1043009
LGZX楼主2024/7/25 20:42
#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

2024/7/25 20:42
加载中...