这个比较简单
#include<iostream>
//#include<cmath>
using namespace std;
void main(){
int n;
cin >> n;
int j = 0;
for (int i = 1; i < n+1; i++){
if (0 == (i % 7)){
j++;
}
else if (7 == (i % 10)){
j++;
}
else if (7 == ((i / 10) % 10)){
j++;
}
else if (7 == ((i / 100) % 10)){
j++;
}
else if (7 == ((i / 1000) % 10)){
j++;
}
}
cout << j;
//system("pause");
}
- #include<iostream>
- using namespace std;
- int main()
- { int N;
- int i=1;
- int count=0;
- cin>>N;
- while(i<=N)
- {if(i%10==7||i%7==0||(i/10)%10==7||(i/100)%10==7||(i/1000)%10==7||(i/10000)%10==7)
- count++;
- i++;
- }
- cout<<count<<endl;
- return 0;
- }