【问题描述】
游戏规则:玩家每次从当前方块跳到下一个方块,如果没有调到下一个方块上则游戏结束。如果跳到了方块上,但没有调到方块中心则获得1分;跳到方块中心时,
若上一次得分为1分或这是本局的第一次跳跃则此次得分为2分,否则此次的得分比上一次得分多两分(即连续跳到方块的中心时,总得分将+2,+4,+6…)
【输入格式】
输入包含多个数字,用空格分隔,每个数字都是1,2,0之一,1表示此次跳跃跳到了方块上但是没有跳到中心,2表示跳到了中心,0表示没有跳到方块上(游戏结束)
输入不超过30个数字,且以0结尾
【输出格式】
输出一个整数,为本剧游戏的得分
【样例输入】
1 1 2 2 2 2 1 1 2 2 0
【样例输出】
22
#include<iostream>
using namespace std;
int main() {
int * procedure = new int[30];
int x = 0;
cin >> procedure[x];
while (procedure[x] != 0) {
x++;
cin >> procedure[x];
}
int score = 0;
int pre = 0;
int time = 0;
for (int i = 0; i <= x; i++) {
if (procedure[i] == 1) {
score += 1;
if (pre == 2)
time = 0;
}
else if (procedure[i] == 2) {
time++;
if (pre == 1 || i == 0)
score += 2;
else
score += time * 2;
}
else if (procedure[i] == 0) {
break;
}
pre = procedure[i];
}
cout << score << endl;
return 0;
}