【幸运数 / A】
题目
代码
#include <bits/stdc++.h>
using namespace std;
bool check(int num)
{int cnt = 0;int x = num;while (x){cnt++;x /= 10;}if (cnt % 2)return false;cnt /= 2;int sum = 0, half = 0, i = 0;x = num;while (x){i++;if (i <= cnt)half += x % 10;sum += x % 10;x /= 10;}if (sum == 2 * half)return true;return false;
}
int main()
{int cnt = 0;for (int i = 1; i <= 1e8; i++){if (check(i))cnt++;}cout << cnt;
}