CCF CSP Brush Question Record 23-201803-1 Jump one jump (Java)

Question number: 201803-1
Question name: Jump around
time limit: 1.0s
Memory limit: 256.0MB
Problem Description:

Problem Description

  Recently, the little game of Jump is popular all over the country and is loved by many players.
  The simplified jump-jump rules are as follows: every time the player jumps from the current square to the next square, the game ends if it does not jump to the next square.
  If you jump to the square but do not jump to the center of the square, you get 1 point; when you jump to the center of the square, if the previous score was 1 point or this is the first jump in the game, the score this time is 2 points. Otherwise, the score this time is two points more than the previous score (that is, the total score will be +2, +4, +6, +8...).
  Now give a person the whole process of jumping, please find his score in this game (according to the rules described in the title).

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 did not jump to the center, 2 means that the jump jumped to the square and jumped to the center In the center of the square, 0 means that the jump did not jump to the square (the game is over).

Output format

  Output an integer, the score of this game (under the rules of this question).

Sample input

1 1 2 2 2 1 1 2 2 0

Sample output

22

Data size and convention

  For all evaluation use cases, no more than 30 numbers are entered, and 0 appears exactly once and is the last number.

 

import java.util.Scanner;
public class 跳一跳 {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[] a=new int[30];
		for(int i=0;i<30;i++){
			a[i]=sc.nextInt();
			if(a[i]==0){
				break;
			}
		}
		int c=0;
		int score=0;
		for(int i=0;i<30;i++){
			if(a[i]==1){
				score+=1;
				c=0;
			}else if(a[i]==2){
				
				c++;
				score+=c*2;
			}
		}
		System.out.println(score);
	}

}

 

Guess you like

Origin blog.csdn.net/m0_37483148/article/details/108363573