CCF认证201803-1 跳一跳
import java.util.Scanner; public class Jump { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int totalScore = 0; int preScore = 0; while(sc.hasNextInt()){ int flag = sc.nextInt(); int score = 0; if(flag == 0){ break; }else if(flag == 1){ //跳上方块没有跳到中心,总分+1 score +=1; preScore = 1; totalScore += score; }else if(flag == 2){ //跳上方块并且跳到中心,上次分数+2+总分 if(preScore == 1){ score = 2; }else{ score = preScore + 2; } preScore = score; totalScore += score; } } System.out.println(totalScore); } }
版权声明:本文为syq816原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。