一二三四五 上山打老虎

CCF-CSP-2018-03-1跳一跳

题目链接:http://118.190.20.162/view.page?gpid=T73

代码:

#include<bits/stdc++.h>

using namespace std;
int a[(int)1e6+5];
int b[(int)1e6+5];
int main (){
    int num;
    int tot=0;
    while(cin>>num){
        a[tot]=num;
        if(num==0)break;
        if(num==1)b[tot]=1;
        else if(tot!=0&&a[tot-1]==1)b[tot]=2;
        else if(tot==0&&num==2)b[tot]=2;
        else b[tot]=b[tot-1]+2;

        tot++;
    }
    int ans=0;
    for(int i=0;i<tot;i++)ans+=b[i];
    cout<<ans<<endl;
    return 0;
}

/*
1 1 2 2 2 1 1 2 2 0
*/

posted @ 2021-03-21 21:55  黒川川  阅读(34)  评论(0)    收藏  举报