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
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 5357 - Dedupe [C++/python] (0) | 2023.03.02 |
---|---|
[BOJ/백준] 5341 - Pyramids [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 4589 - Gnome Sequencing [C++/python] (0) | 2023.03.01 |
[BOJ/백준] 4470 - 줄 번호 [C++/python] (0) | 2023.03.01 |
[BOJ/백준] 3765 - Celebrity jeopardy [C++/python] (0) | 2023.03.01 |