백준 #27159번 노 땡스!

jhj·2024년 5월 22일

백준 JAVA

목록 보기
492/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int total = 0;
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++) {
			int count = 0;
			for(int j = i; j < n - 1; j++) {
				if(a[j + 1] == a[j] + 1) {
					count++;
				}else {
					break;
				}
			}
			total += a[i];
			i = i + count;
		}
		System.out.println(total);
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글