기술 블로그

1065번 한수 본문

알고리즘 문제/BOJ

1065번 한수

parkit 2018. 12. 18. 09:33
728x90
반응형

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


간단한 구현 및 브루트포스 문제다.


문제에서 어느 순서에서 빼는지(예: 백의 자리 - 십의 자리인지 십의 자리 - 백의 자리 등등)


언급을 안 해서, 둘 다 만족하면, 한수로 체크하였는데, 다행히 통과되었다.



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
40
41
42
43
44
45
46
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
 
using namespace std;
 
bool num[1001= { false, };
 
void HanSoo()
{
    for (int i = 1; i <= 999; i++)
        if (i <= 99) num[i] = true;    
        else if (100 <= i && i <= 999)
        {
            int hun = i / 100;
            int ten = (i % 100/ 10;
            int one = (i % 100) % 10;
 
            if (hun - ten == ten - one)
                if (one - ten == ten - hun)
                    num[i] = true;            
        }
}
 
int main(void)
{
    int N = 0, cnt = 0;
 
    HanSoo();
 
    scanf("%d"&N);
 
    for (int i = 1; i <= N; i++)
        if (num[i]) ++cnt;
    
    printf("%d\n", cnt);
 
    return 0;
}
cs


728x90
반응형

'알고리즘 문제 > BOJ' 카테고리의 다른 글

9372번 상근이의 여행  (0) 2018.12.19
2231번 분해합  (0) 2018.12.18
2161번 카드1  (0) 2018.12.15
1018번 체스판 다시 칠하기  (0) 2018.12.14
2512번 예산  (0) 2018.12.13