solution.cpp 314 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
using namespace std;

int ans;
int cal(int n)
{
    int sum = 0;
    while (n)
    {
        if (n % 10 == 2)
            sum++;
        n /= 10;
    }
    return sum;
}
int main()
{
    for (int i = 1; i <= 2020; i++)
    {
        ans += cal(i);
    }
    cout << ans << endl;
    return 0;
}