题解 | 挑7

挑7

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

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

int main() {
    int a;
    cin >> a;
    if (a < 7) {
        return 0;
    }
    int count = 0;
    for (int i = 7 ; i <= a; i++) {
        string temp = to_string(i);
        if (i % 7 == 0) {
            count++;
        } else {
            for (char c : temp) {
                if (c == '7') {
                    count++;
                    break;
                }
            }
        }
    }
    cout <<count<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

开心,这题一遍过,嘿嘿

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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