CSP:跳一跳
满分代码
#include <iostream>
using namespace std;
int a[30];
int main()
{
int x;
int ans = 0;
int pre = 0;
do {
cin >> x;
if (x == 1) {
ans += 1;
pre = 1;
}
else if (x == 2) {
if (pre < 2) { // 第一次跳或者前一次为1
ans += 2;
pre = 2;
}
else { // 前一次为2
ans += pre + 2;
pre += 2;
}
}
} while(x != 0);
cout << ans << endl;
return 0;
}