(练习用)挑7(HJ55)

一:解题思路

二:完整代码示例 (C++版和Java版)

C++:

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

using namespace std;

int count(int n)
{
    int counts = 0;

    for (int m = 7; m <= n; m++)
    {
        if (m % 7 == 0) counts++;
        else
        {
            string temp = to_string(m);
            if (temp.find("7") != -1) counts++;
        }
    }

    return counts;
}

int main()
{
    int n = 0;

    while (cin >> n)
    {
        cout << count(n) << endl;
    }

    return 0;
}

 

posted @ 2020-08-03 21:11  repinkply  阅读(237)  评论(0)    收藏  举报