歡迎通路我的CCF認證解題目錄
題目描述

思路過程
直接模拟即可
代碼
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int ans = 0;
int pre = 1;//上一次的得分
int type = in.nextInt();//跳躍的類型
while ( type != 0 ) {
if ( type == 1 ) {//不為中心
pre = 1;
ans += 1;
} else {
if ( pre == 1 ) {//上一次不是中心
pre = 2;
ans += pre;
} else {
pre += 2;
ans += pre;
}
}
type = in.nextInt();
}
System.out.println(ans);
}
}