(练习用)挑7(HJ55)
一:解题思路
二:完整代码示例 (C++版和Java版)
C++:
#include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; int count(int n) { int counts = 0; for (int m = 7; m <= n; m++) { if (m % 7 == 0) counts++; else { string temp = to_string(m); if (temp.find("7") != -1) counts++; } } return counts; } int main() { int n = 0; while (cin >> n) { cout << count(n) << endl; } return 0; }

浙公网安备 33010602011771号