题解 | #挑7#
挑7
https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
#include <iostream> #include <string> #include <vector> using namespace std; int count_num(int n) { int count = 0; //对符合条件的数进行计数 for (int i = 1; i <= n; i++) { if (i % 7 == 0) { count++; } else { string str = std::to_string(i); string str1 = std::to_string(7); if (str.find(str1) != string::npos) { count++; } } } return count; } int main() { int n; cin >> n; cout << count_num(n) << endl; } // 64 位输出请用 printf("%lld")