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. 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);
}
}