"SWEA 3750 Digit sum"의 두 판 사이의 차이

(새 문서: ==개요== ;{{PAGENAME}} {{SWEA 헤더}} {{SWEA 난이도 3-4}} |} ==C++== <source lang='cpp'> </source> ==Java== <source lang='java'> import java.io.*; import java.util.*; public...)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
7번째 줄: 7번째 줄:


==C++==
==C++==
<source lang='cpp'>
<syntaxhighlight lang='cpp'>
</source>
</syntaxhighlight>


==Java==
==Java==
<source lang='java'>
<syntaxhighlight lang='java'>
import java.io.*;
import java.io.*;
import java.util.*;
import java.util.*;
36번째 줄: 36번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>

2021년 7월 31일 (토) 10:58 기준 최신판

1 개요[ | ]

SWEA 3750 Digit sum
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 3-4

2 C++[ | ]

3 Java[ | ]

import java.io.*;
import java.util.*;
public class Solution {
	static long f(long n) {
		long sum;
		for(sum=0; n>0; n/=10 ) sum += n%10;
		return sum;
	}
	static long F(long n) {
		for(; n>=10; ) n = f(n);
		return n;
	}
	public static void main(String[] args) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    	int T = sc.nextInt();
    	for(int tc=1; tc<=T; tc++) {
    		long N = sc.nextLong();
    		bw.append(String.format("#%d %d\n", tc, F(N)));
        }
    	bw.flush();
        sc.close();
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}