Zerojudge 基礎題庫a147 Print it all


這題也是一道簡單的題目
"若 n = 0 表示資料結束" 這句話可以忽略。

C++ 程式碼:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
/*
大於 0、整數、不可以被 7 整除、小於 n
n = 1時
1 % 7 != 0? Yes

*/
bool check_if_okay(int inputA)
{
    if (inputA % 7 != 0)
    {
        return true;
    }
    else
    {
        return false;
    }

}
int main()
{
    int n;
    while(cin >> n)
    {
        for (int i = 0; i < n; i++)
        {
            if (check_if_okay(i) == true)
            {
                cout << i << " ";
            }
        }
        cout << endl;
    }
}

留言

這個網誌中的熱門文章

Zerojudge 基礎題庫a004 文文的求婚 (Python)

紙蜻蜓的受風面積與紙蜻蜓落地時間的關係 #1 [實驗歷程與Python Matplotlib]

Zerojudge 基礎題庫a013 羅馬數字 (Python)