πŸ“š μ½”λ”©ν…ŒμŠ€νŠΈ/λ°±μ€€ & ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€

[SWEA][JAVA]D3 : μƒμ›μ΄μ˜ 연속 ν•©

deep_lee 2022. 11. 15. 14:24

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AWoEzJFa2A4DFARq&categoryId=AWoEzJFa2A4DFARq&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=7 

 

SW Expert Academy

SW ν”„λ‘œκ·Έλž˜λ° μ—­λŸ‰ 강화에 도움이 λ˜λŠ” λ‹€μ–‘ν•œ ν•™μŠ΅ 컨텐츠λ₯Ό ν™•μΈν•˜μ„Έμš”!

swexpertacademy.com

 


νˆ¬ν¬μΈν„° μ•Œκ³ λ¦¬μ¦˜λ§Œ μ“°λ©΄ 끝

 

 

import java.util.Scanner;
class Solution{
    public static void main(String args[]) throws Exception{
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int n=kb.nextInt();
            int[] arr=new int[n];
            for(int i=0; i<n; i++) arr[i]=i+1;
 
            int sum=0; // 15
            int cnt=0;
            int lt=0;
            for(int rt=0; rt<n; rt++){
                sum+=arr[rt];
                if(sum==n)
                    cnt++;
                while(sum>=n){
                    sum-=arr[lt++];
                    if(sum==n)
                        cnt++;
                }
            }
            System.out.println("#"+t+" "+cnt);
        }
    }
}