#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;
}

어려운게 없었던 문제. 

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

'🖥️ CS > Baekjoon Algorithms' 카테고리의 다른 글

#1712번 손익분기점 (c++)  (0) 2020.02.12
#1316번 그룹단어체커 (c++)  (0) 2020.02.11
#4673번 셀프넘버 (c++)  (0) 2020.02.08
#1008번 A/B (c++)  (0) 2020.01.14
#4604번 Steganography (c++)  (0) 2020.01.13