题解 | #挑7#

挑7

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

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> res;
    int temp;
    for (int i = 7; i <= n; ++i) {
        int tmp = i;
        if (i % 7 == 0) {
            res.push_back(i);
        } else {
            for (int j = 0; j < 4; ++j) {
                temp = tmp % 10;
                if(temp == 7){
                    res.push_back(i);
                    break;
                }
                tmp /= 10;
            }
        }
    }
    // for(auto &i : res){
    //     cout << i << " ";
    // }
    cout << res.size() << endl;

    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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