题解 | #挑7#

挑7

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

#include <iostream>
#include <string>
#include <vector>


using namespace std;

int count_num(int n) {
    int count = 0; //对符合条件的数进行计数
    for (int i = 1; i <= n; i++) {
        if (i % 7 == 0) {
            count++;
        } else {
            string str = std::to_string(i);
            string str1 = std::to_string(7);
            if (str.find(str1) != string::npos) {
                count++;
            }
        }
    }
    return count;
}
int main() {
    int n;
    cin >> n;
    cout << count_num(n) << endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

点赞 评论 收藏
分享
06-17 21:57
门头沟学院 Java
白友:噗嗤,我发现有些人事就爱发这些,明明已读不回就行了,就是要恶心人
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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