- 问题链接:跳一跳
- 问题分析:模拟法解决。
- 程序说明:number表示输入的数字;count记录连续得2的次数;res记录得分
- 程序代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int number = reader.nextInt();
int count = 1;
int res = 0;
while(number!=0) {
if(number==1) {
res++;
count = 1;
}
else {
res = res+count*number;
count++;
}
number = reader.nextInt();
}
System.out.println(res);
}
}