알고리즘

[알고리즘] 백준 17614 - 369 (C++)

blueberrysoda 2024. 10. 4. 21:25

[문제 링크] : https://www.acmicpc.net/problem/17614

#include <iostream>
using namespace std;

int N, Ans;

int solve(int n){
    int cnt = 0, tmp = n;
    while(tmp){
        if(tmp % 10 == 3 || tmp % 10 == 6 || tmp % 10 == 9){
            cnt++;
        }
        tmp /= 10;
    }
    return cnt;
}

int main(){
    cin >> N;
    for(int i=1; i<=N; i++){
        Ans += solve(i);
    }
    cout << Ans << "\n";
    return 0;
}