CSP 试题编号201803-1 Java实现

时间:2023-05-09 18:59:32

import java.util.Scanner;

public class Main{

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = -1;
int score = 0;
int prior = 0;
//当输入0时 游戏结束 计算分数
while((num=input.nextInt())!=0){
if(num==1){
score = score+1;
prior = 1;
}
else if(num==2){
if(prior==0||prior==1){
score = score+2;
prior = 2;
}
else{
score = score+prior+2;
prior = prior+2;
}
}
}
System.out.println(score);
}

}