Notice
Recent Posts
Recent Comments
Link
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