Deep_Lee

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWxpQia60FgDFAWL 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 

 


0๊ณผ 1์ผ ๊ฒฝ์šฐ์—๋งŒ ๋”ํ•˜๋Š”๊ฒŒ ์ข‹๊ณ , ๋‚˜๋จธ์ง€๋Š” ๊ณฑํ•˜๋Š”๊ฒŒ ์ตœ๋Œ€์ˆ˜๋ฅผ ๋ฝ‘์„ ์ˆ˜ ์žˆ์Œ.

๊ทผ๋ฐ ๋ง์…ˆ ํ˜น์€ ๊ณฑ์…ˆ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ณ€์ˆ˜ result๊ฐ€ 1์ดํ•˜์ผ๋•Œ๋„ ๋ง์…ˆ์„ ํ•ด์ค˜์•ผํ•จ .

 

( ๊ทธ ๋ฐ–์— ์ฃผ์˜ํ• ์ ์€ ์ž…๋ ฅ๊ฐ’์ด 1๊ฐœ์ผ๋•Œ ? ๋‚ด๊ฐ€ ์ง  ์ฝ”๋“œ๋กœ๋Š” ๋ฌธ์ œ๋˜์ง„์•Š์•˜์Œ ) 

 

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 n=1; n<=T; n++){
            int num=kb.nextInt();
            int[] arr=new int[num];
            for(int i=0; i<num; i++) arr[i]=kb.nextInt();
 
            int result=0;
            for(int i=0; i<num; i++){
                if(arr[i]<=1||result<=1)
                    result+=arr[i];
                else
                    result*=arr[i];
            }
            System.out.println("#"+n+" "+result);
        }
    }
}