File tree Expand file tree Collapse file tree
프로그래머스/0/181914. 9로 나눈 나머지 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ class Solution {
2+ public int solution (String number ) {
3+ int answer = 0 ;
4+
5+ int length = number .length ();
6+
7+ for (int i =0 ; i <length ; i ++){
8+ char tmp = number .charAt (i );
9+
10+ answer += tmp - '0' ;
11+ }
12+
13+ answer %= 9 ;
14+
15+
16+ return answer ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ # [ level 0] 9로 나눈 나머지 - 181914
2+
3+ [ 문제 링크] ( https://school.programmers.co.kr/learn/courses/30/lessons/181914 )
4+
5+ ### 성능 요약
6+
7+ 메모리: 78.3 MB, 시간: 4.21 ms
8+
9+ ### 구분
10+
11+ 코딩테스트 연습 > 코딩 기초 트레이닝
12+
13+ ### 채점결과
14+
15+ 정확성: 100.0<br />합계: 100.0 / 100.0
16+
17+ ### 제출 일자
18+
19+ 2026년 03월 27일 17:04:33
20+
21+ ### 문제 설명
22+
23+ <p >음이 아닌 정수를 9로 나눈 나머지는 그 정수의 각 자리 숫자의 합을 9로 나눈 나머지와 같은 것이 알려져 있습니다.<br >
24+ 이 사실을 이용하여 음이 아닌 정수가 <strong >문자열</strong > <code >number</code >로 주어질 때, 이 정수를 9로 나눈 나머지를 return 하는 solution 함수를 작성해주세요.</p >
25+
26+ <hr >
27+
28+ <h5 >제한사항</h5 >
29+
30+ <ul >
31+ <li >1 ≤ <code >number</code >의 길이 ≤ 100,000</li >
32+ <li ><code >number</code >의 원소는 숫자로만 이루어져 있습니다.</li >
33+ <li ><code >number</code >는 정수 0이 아니라면 숫자 '0'으로 시작하지 않습니다.</li >
34+ </ul >
35+
36+ <hr >
37+
38+ <h5 >입출력 예</h5 >
39+ <table class =" table " >
40+ <thead><tr>
41+ <th >number</th >
42+ <th >result</th >
43+ </tr >
44+ </thead >
45+ <tbody><tr>
46+ <td >"123"</td >
47+ <td >6</td >
48+ </tr >
49+ <tr >
50+ <td >"78720646226947352489"</td >
51+ <td >2</td >
52+ </tr >
53+ </tbody >
54+ </table>
55+ <hr >
56+
57+ <h5 >입출력 예 설명</h5 >
58+
59+ <p >입출력 예 #1</p >
60+
61+ <ul >
62+ <li >예제 1번의 <code >number</code >는 123으로 각 자리 숫자의 합은 6입니다. 6을 9로 나눈 나머지는 6이고, 실제로 123 = 9 × 13 + 6입니다. 따라서 6을 return 합니다.</li >
63+ </ul >
64+
65+ <p >입출력 예 #2</p >
66+
67+ <ul >
68+ <li >예제 2번의 <code >number</code >는 78720646226947352489으로 각자리 숫자의 합은 101입니다. 101을 9로 나눈 나머지는 2이고, 실제로 78720646226947352489 = 9 × 8746738469660816943 + 2입니다. 따라서 2를 return 합니다.</li >
69+ </ul >
70+
71+
72+ > 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
You can’t perform that action at this time.
0 commit comments