알고리즘

C++ 알고리즘 - 백준 1065 한수

마루설아 2025. 2. 20. 20:31

https://www.acmicpc.net/problem/1065

 

#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

/******** 전역변수 ********/


/******** 함    수 ********/


int main(void) {
	/******** C++ INIT ********/
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	/******** 지역변수 ********/
	int input;
	int cnt = 0;
	int n100, n10, n1;

	/******** 구    현 ********/
	cin >> input;

	for (int i = 1; i <= input; i++) {
		// 100 미만의 수는 모두 한수
		if (i < 100) {
			cnt++;
		}

		// 100 이상 1000미만의 수는 각 자리수 차이를 구한다
		else if (i < 1000) {
			n100 = i / 100;
			n10 = i / 10 % 10;
			n1 = i % 10;

			if (n100 - n10 == n10 - n1) cnt++;
		}
	}

	cout << cnt;
}