题解 | #挑7#C++,简单,好理解

挑7

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

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int count=0;
        string str;
        for(int i=1;i<=n;i++)
        {
            if(i%7==0)//7的倍数
            {
                count++;
                continue;
            }
            str=to_string(i);//转成字符串
            if(str.find('7')!=str.npos)//字符串查找,如果有7,则加1
            {
                count++;
            }
        }
        cout<<count<<endl;
    }
}
全部评论

相关推荐

11-03 13:18
门头沟学院 Java
包行:平时怎么刷算法题的哇,字节的手撕听说都很难
字节跳动工作体验
点赞 评论 收藏
分享
活泼的代码渣渣在泡池...:哈哈哈挺好的,我也上岸美团了,不说了,我又接了一单
点赞 评论 收藏
分享
评论
3
2
分享

创作者周榜

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