题解 | #挑7#

挑7

https://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int t = 1;
    int cur = 0;
    int weight[5] = {1, 10, 100, 1000, 10000};
    while (t <= n) {
        if(t % 7 == 0) {
            cur++;
            t++;
            continue;
        }
        for(int i = 0; i < 5; i++) {
            if((t / weight[i]) % 10 == 7) {
                cur++;
                break;
            }
        }
        t++;
    }
    cout << cur << endl;
}

全部评论

相关推荐

05-22 17:07
已编辑
广东石油化工学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务