CCP-CSP认证考试 201803-1 跳一跳 c/c++题解
程序员文章站
2024-02-23 21:48:04
...
题目描述:
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int PI = acos(-1);
const int E = exp(1);
const int MOD = 1e9+7;
const int MAX = 1e5+5;
int jmp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int sum = 0;
int preGrade = 1;
while(cin >> jmp && jmp != 0)
{
if(jmp == 1)
{
sum += 1;
preGrade = 1;
}
else if(jmp == 2)
{
if(preGrade == 1) preGrade = 2;
else preGrade += 2;
sum += preGrade;
}
}
cout << sum << endl;
return 0;
}
上一篇: 代码复用