题解 | #挑7#

挑7

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

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

bool containSev(int val){
    if(val%7==0){
        return true;
    }
    string str = to_string(val);
    for(auto ch:str){
        if(ch=='7'){
            return true;
        }
    }
    return false;    
}


int main(){
    int n;
    std::cin >> n;
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(containSev(i)){
            cnt++;
        }
    }
   
    std::cout << cnt;



    return 0;
}

全部评论

相关推荐

04-08 23:37
已编辑
东华大学 结构工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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