파게로그

[백준 1065번] 한수 본문

콤퓨타 왕왕기초/PS

[백준 1065번] 한수

파게 2020. 10. 27. 01:56

문제 링크: 1065번 한수

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

 

n > 10이 아니라 n >= 10이다. 항상 기본적인 것부터 조심하자.

 

#include <iostream>

using namespace std;

bool checkSeq(int n) {
    if (n < 100)
        return true;
    
    int left, right;
    int curSub;
    int lastSub = 10;
    while (n >= 10) { // 여기!
        right = n % 10;
        n /= 10;
        left = n % 10;
        
        curSub = right - left;
        if (curSub != lastSub) {
            if (lastSub == 10) {
                lastSub = curSub;
                continue;
            }
            return false;
        }
        lastSub = curSub;
    }
    
    return true;
}

int main(void) {
    int N;
    cin >> N;
    
    int answer = 0;
    for (int i = 1; i <= N; i++)
        if (checkSeq(i))
            answer++;
    
    cout << answer;
    
    return 0;
}
Comments