题解 | #挑7#
挑7
http://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
#include<bits/stdc++.h> using namespace std; int main() { int n; while(cin>>n) { int count=0; //记录与7有关的数字的个数 for(int i=1;i<=n;i++) { if(i%7==0){ //该数是7的倍数 count++; continue; }else if(i%10==7) { //该数的个位数是7 count++; continue; }else if(i%100/10==7) { //该数的十位数是7 count++; continue; }else if(i%1000/100==7) {//该数的百位数是7 count++; continue; }else if(i%10000/1000==7) {//该数的千位数是7 count++; continue; } } cout<<count<<endl; } return 0; }