201803-1 跳一跳 Java

思路:
一个变量plus记录叠加的数,遇到2就+2

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int next = sc.nextInt();
		int score = 0;
		int plus = 0;
		while(next != 0) {
			if(next == 1) {
				plus = 0;
				score += 1;
			}else if(next == 2){
				plus += 2;
				score += plus;
			}
			next = sc.nextInt();
		}
		sc.close();
		System.out.println(score);
	}

}
posted @ 2020-02-27 11:17  菜鸡A  阅读(102)  评论(0编辑  收藏  举报