题解 | #挑7#
挑7
https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
#include<iostream> using namespace std; bool handle( int i ){ // 1.先判断数字中含不含7 int copy = i; while(i){ int cur = i % 10; // cout << "当前位上数字:" << cur << endl; if( cur == 7 ){ return true; } i /= 10; } // 2. 判断是不是7的倍数 int resident = copy % 7; // cout << "对7取模:"<< resident << endl; if(!resident) return true; return false; } int main(){ int n; cin >> n; int ans = 0; for(int i =1 ; i <=n ; i++){ // cout << "当前处理的数字:" << i << endl; bool res = handle(i); // cout <<res << endl; if(res) ans++; } cout <<ans; }