Deep_Dev

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

 

SW Expert Academy

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

swexpertacademy.com

 

 


์ž๋ฆฟ์ˆ˜ ๋ง์…ˆ + ํ˜•๋ณ€ํ™˜์„ ์ด์šฉํ•ด์„œ ํ’€์—ˆ๋Š”๋ฐ

ํ˜•๋ณ€ํ™˜์„ ๋งŽ์ดํ•ด์„œ ๊ทธ๋Ÿฐ์ง€ ์ƒ๊ฐ๋ณด๋‹ค ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํฌ๋‹ค ..

 

 

 

import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            long n=kb.nextInt();
            if(n<10) {
                System.out.println("#" + t + " " + n);
                continue;
            }
            int sum=0;
            String s=String.valueOf(n);
            while(s.length()>=2){
                String[] arr=s.split("");
                for(int i=0; i<arr.length; i++) {
                    sum += Integer.parseInt(arr[i]);
                }
                s=String.valueOf(sum);
                sum=0;
            }
            System.out.println("#"+t+" "+s);
        }
    }
}