Algorithm/PS

[BOJ/백준] 5300 - Fill the Rowboats! [C++/python]

chanwoong1 2023. 3. 2. 11:10
728x90

문제 번호

 

5300번: Fill the Rowboats!

The output will be the number of each pirate separated by spaces, with the word ”Go!” after every 6th pirate, and after the last pirate.

www.acmicpc.net

문제 풀이

6의 배수일때 혹은 마지막 수 출력 이후 "Go!"를 출력하는 문제이다.

정답 코드

C++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define fast ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define ll long long

int main() {
    fast;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cout << i << " ";
        if (i % 6 == 0 || i == n) cout << "Go! ";
    }
}

python

n = int(input())
for i in range(1, n + 1) :
    print(i, end = " ")
    if (i % 6 == 0 or i == n) :
        print("Go!", end = " ")
728x90