CCF certification 201803-1 hop hop

Original title link: http://118.190.20.162/view.page?gpid=T73

Welcome to my CCF certification exam problem solution directory https://blog.csdn.net/richenyunqi/article/details/80210763

Problem Description
Question number: 201803-1
Question name: jump
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:
Problem Description
  Recently, this little game of jumping has become popular all over the country and is loved by many players.
  The simplified jump-and-jump rule is as follows: the player jumps from the current block to the next block each time, and the game ends if he does not jump to the next block.
  If you jump to the block but not to the center of the block, you will get 1 point; when you jump to the center of the block, if the previous score is 1 point or this is the first jump in this game, the score will be 2 points. Otherwise, the score this time is two points more than the previous one (ie, when jumping to the center of the square continuously, the total score will be +2, +4, +6, +8...).
  Now, given the whole process of a person jumping, please ask him for the score of this game (according to the rules described in the question).
input format
  The input contains multiple numbers, separated by spaces, each number is one of 1, 2, 0, 1 means that the jump jumped to the square but not the center, 2 means that the jump jumped to the square and jumped to The center of the block, 0 means that the jump did not jump to the block (the game is over at this point).
output format
  Output an integer, which is the score of the game (under the rules of this question).
sample input
1 1 2 2 2 1 1 2 2 0
Sample output
22
数据规模和约定
  对于所有评测用例,输入的数字不超过30个,保证0正好出现一次且为最后一个数字。


c++代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a=1,score=0,num=0;//a存储输入数据,score为最终得分,num为连跳方块中心次数
    while(~scanf("%d",&a)&&a!=0)//数据输入还没完成且a!=0
        if(a==1){//如果a==1
            score+=a;//加上1分
            num=0;//连跳方块中心次数归零
        }else if(a==2)//a==2
            score+=2*(++num);//递增连跳方块中心次数,得分为该次数乘2
    printf("%d",score);
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325738126&siteId=291194637