🖥️ CS/Baekjoon Algorithms

#1065번 한수 (c++)

한국의 메타몽 2020. 2. 8. 22:24
#include <iostream>
using namespace std;

bool check(int a)
{
    if(((a/100)-(a/10)%10)==((a/10)%10-a%10))
        return true;
    else
        return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int ans = 0;
    int get = 0;

    cin >> get;
    
    bool num[1001]; // 0~1000개
    for(int i=0; i<=1000; i++)
    {
        if(i<100)
            num[i]=true;
        else if (i>=100&&i<1000)
        {
            if(check(i)==true)
                num[i]=true;
            else
                num[i]=false;
        }
        else
            num[i]=false;
    }
    
    for(int i=0; i<=get; i++)
    {
        if(num[i]==true)
            ans++;
    }
    
    cout << ans-1 << "\n";
    
    return 0;
}

어려운게 없었던 문제. 

코드가 길어보이지만 읽어보면 지극히 단순하다.