题解 | #挑7#
挑7
https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
#include <stdio.h> int main() { int a; int cnt = 0; scanf("%d",&a); for (int i=1; i<=a; i++) { int temp = i; if(temp%7 == 0) cnt++; else if (temp % 10 ==7){ cnt++; }else if ((temp/10)%10 ==7&& temp >=10) { cnt++; }else if ((temp/100)%10 ==7&& temp >=100) { cnt++; }else if ((temp/1000)%10 ==7&& temp >=1000) { cnt++; }else if ((temp/1000)%10 ==7&& temp >=10000) { cnt++; } } printf("%d",cnt); return 0; }