a147.Print it all

a147.Print it all


解題思路 : 用while迴圈重複輸入n,for迴圈中,如果小於n的i值不可被7整除則輸出

程式碼

/*
a147. Print it all
skyblue
https://zerojudge.tw/ShowProblem?problemid=a147
AC (6ms, 304KB) 
*/

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;

    while(cin >> n){
        if(n>0){
            for(int i=1; i<n; i++){
                if(i%7 != 0){
                    cout << i <<" ";
                }
            }
            cout << "\n";
        }
        else if(n == 0)
            break;
    }
    return 0;
}

留言

這個網誌中的熱門文章

b971 等差數列

c290. APCS 2017-0304-1秘密差

i213. stack 練習