알고리즘/삼성 SW expert Academy

[SWEA] 8658. Summation_JAVA

뇌장하드 2022. 5. 24. 21:52

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

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

간단한 구현 문제이다.

import java.util.Scanner;
import java.io.FileInputStream;

class Solution{
    public static void main(String args[]) throws Exception{
        Scanner sc = new Scanner(System.in);
        int T=sc.nextInt();
        sc.nextLine();
        for(int test_case = 1; test_case <= T; test_case++) {
            String str= sc.nextLine();
            String[] stars=str.split(" ");
            int max=0;
            int min=999999999;
            for(String s:stars){
                int sum=0;
                    for(char c :s.toCharArray()){
                        sum+=c-48;
                    }
                    if(max<sum) max=sum;
                    if(min>sum) min=sum;
            }
            System.out.println("#"+test_case+" "+max+" "+min );
        }
    }
}