본문 바로가기

Dev/BAEKJOON 백준

[백준/BOJ] 백준 코딩 알고리즘 1065번/C++

728x90
반응형

백준 코딩 알고리즘 문제 1065

 

백준 코딩 알고리즘 문제 1065번 풀이 - 사용 언어: C++

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
32
33
34
35
36
37
38
39
#include <iostream>
 
using namespace std;
 
int main() {
 
    int N;
    int count = 0;
    int third, second, first;
    int temp;
 
    cin >> N;
 
    //Vacuous truth에 의해!
    if (N < 100) {
        cout << N;
    }
    else {
        if (N == 1000) N = 999;
        for (int i = 100; i <= N; i++) {
            temp = i;
            
            first = temp % 10;
            temp /= 10;
 
            second = temp % 10;
            temp /= 10;
 
            third = temp % 10;
            temp /= 10;
 
            if ((third - second) == (second-first))
                count++;
        }
        cout << 99 + count;
    }
 
    return 0;
}
cs
728x90
반응형