欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CCP-CSP认证考试 201803-1 跳一跳 c/c++题解

程序员文章站 2024-02-23 21:48:04
...

CCF-CSP认证考试题解目录By东瓜lqd

题目描述:
CCP-CSP认证考试 201803-1 跳一跳 c/c++题解
代码:

#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;
}