Notice
Recent Posts
Link
Tags
- @transactional
- Docker
- hibernate
- static
- java
- join
- ORM
- DI
- 자바
- spring boot
- string
- springboot
- spring security 6
- select
- sql
- jpa
- 문자열
- AWS
- 스프링
- Django
- spring mvc
- spring
- 1차원 배열
- mysql
- 데이터베이스
- SSL
- 프로그래머스
- PYTHON
- nginx
- 스프링부트
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Archives
개발하는 자몽
[1065] 함수 - 한수 본문
문제

코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
// 1. 한 자리 숫자는 한수로 정의
// 2. 두 자리 숫자는 모두 공차가 정해진 등차수열이므로 한수임
// 3. 세 자리 숫자는 공차를 계산해 등차수열인지 확인 필요
// 4. 입력값은 1000 이하의 숫자, 1000은 한수가 아니므로 세 자리 숫자가 등차수열인지 확인
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
if (n < 100) { //한 자리 수 ~ 두 자리 수
System.out.println(n);
} else {
int res = 99;
for (int i = 111; i <= n; i++) {
res += han(i);
}
System.out.println(res);
}
}
private static int han(int n) {
int hun = n / 100;
int ten = n % 100 / 10;
int one = n % 10;
if (ten * 2 == hun + one) {
return 1;
}
return 0;
}
}
'Algorithm' 카테고리의 다른 글
| [11720]문자열 - 숫자의 합 (0) | 2022.04.13 |
|---|---|
| [11654]문자열 - 아스키 코드 (0) | 2022.04.12 |
| [4673] 함수 - 셀프 넘버 (0) | 2022.04.10 |
| [15596] 함수 - 정수 N개의 합 (0) | 2022.04.09 |
| [4344] 1차원 배열 - 평균은 넘겠지 (0) | 2022.04.01 |
Comments