1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <iostream> #include <vector> using namespace std; bool HS(int N); int main() { int N, t = 0; cin >> N; if (N >= 1 && N <= 1000) { for (int i = 1; i <= N; i++) { if (HS(i) == 1) t += 1; } cout << t << endl; } } bool HS(int N) { vector<int> v; int n = N; for (int i = 0; i < 4; i++) { if (n > 0) { v.push_back(n % 10); n /= 10; } } if (N == 1000) return 0; if (N > 99 && N < 1000) { if (v[2] – v[1] == v[1] – v[0]) return 1; else return 0; } else return 1; } | cs |