Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 정석학술정보관
- 구현
- 컴퓨터공학과
- 스택
- 백준
- 그래프
- 코딩
- 너비우선탐색
- 개발
- 컴공과
- 알고리즘
- DP
- 북리뷰
- 정석
- 오퍼레이팅시스템
- c++
- bfs
- 코테
- Computer science
- 브루트포스
- 컴공
- OS
- vector
- Operating System
- 오에스
- 자료구조
- 문제풀이
- cs
- coding
- Stack
Archives
- Today
- Total
Little Jay
[C++] 백준 1065번 - 한수 본문
1~99까지의 숫자는 모두 한수 이다.
등차수열을 생각하면 원소를 더하는 경우와 빼는 경우, 공차가 0인 경우 모두 생각하자
#include <iostream>
#include <cmath>
using namespace std;
int calc(int n) {
int count = 0;
int first, second, third;
if (n < 100)
return n;
else {
for (int i = 100; i <= n; i++) {
first = i / 100;
second = (i % 100) / 10;
third = (i % 100) % 10;
if ((first - second) == (second - third)) {
count++;
}
}
return (99 + count);
}
}
int main() {
int n;
cin >> n;
cout << calc(n) << '\n';
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 15683번 - 감시 (0) | 2021.09.18 |
---|---|
[C++] 백준 2941번 - 크로아티아 알파벳 (0) | 2021.09.07 |
[C++] 백준 5052번 - 전화번호 목록 (0) | 2021.09.04 |
[C++] 백준 1110번 - 더하기 사이클 (0) | 2021.09.03 |
[C++] 백준 1789번 - 수들의 합 (0) | 2021.09.02 |
Comments