题解 | 挑7
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
int count = 0;
for (int i = 7; i < n + 1; i++) {
if (i % 7 == 0 || to_string(i).find('7') != EOF) { //7的倍数或者能找到7,用find函数实现,先转化为字符串,如果没找到7会返回为EOF,满足一项则+1
count++;
}
}
cout << count;
}
// 64 位输出请用 printf("%lld")

阿里云成长空间 702人发布