백준 1110번 www.acmicpc.net/problem/1110
풀이
두 자리 정수의 합을 일의 자리로, 원래 두 자리 정수를 십의 자리수로 두는 문제이다. 계속해서 원래의 값이 나올 수 있도록 해야 하므로 do-while 문을 이용해서 푼다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import java.util.Scanner;
public class while_1110 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input = sc.nextInt();
int x = input;
int cycle = 0;
do {
x = x%10*10 + (x/10+x%10)%10;
cycle++;
} while(input!=x);
System.out.println(cycle);
}
public static int cnt(int x) {
int t = 1;
if(x/10!=0) {
x=x/10;
t++;
}
return t;
}
}
|
cs |
'알고리즘과 코테' 카테고리의 다른 글
[JAVA | 백준 10818] 최대, 최소 (0) | 2021.03.17 |
---|---|
[Java | 백준 1546] 평균 (0) | 2021.03.17 |
[JAVA | 백준 9498] 시험성적 (0) | 2021.03.16 |
[JAVA | 백준 1085] 직사각형에서 탈출 (0) | 2021.03.08 |
[JAVA | 백준 1193] 분수찾기 (0) | 2021.03.08 |
댓글
최근에 올라온 글
TAG
- git연동
- 웹페이지만들기
- LifecycleException
- gradle
- 실용주의프로그래머
- IT 5분 잡학사전
- JIRA
- intellij
- java
- putty
- jdbc
- 노개북
- EC2
- 오늘의코딩
- 독서후기
- gradle build
- 기술블로그
- ubuntu
- spring
- 노마드코더
- 정보처리기사 실기
- AWS
- filezila
- 개발도서
- 정보처리기사
- SQLD
- 호스팅영역
- 북클럽
- 배포
- 정보처리기사 필기
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함