슈콩

[SWEA] Digit sum 본문

Algorithms/SWEA

[SWEA] Digit sum

shukong 2025. 11. 18. 22:09

 

 

[문제]

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

 

SW Expert Academy

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

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			String n = br.readLine();
			while(n.length()!=1) {
				int num = 0;
				for(int i=0;i<n.length();i++) {
					num += n.charAt(i) - '0';
				}
				n = String.valueOf(num);
			}
			System.out.println("#"+tc+" "+n);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 그래프의 삼각형  (0) 2025.11.19
[SWEA] 보충학습과 평균  (0) 2025.11.19
[SWEA] 동철이의 프로그래밍 대회  (0) 2025.11.18
[SWEA] 두가지 빵의 딜레마  (0) 2025.11.18
[SWEA] 일요일  (0) 2025.11.18