본문 바로가기
BaekJoon/Bronze

[BOJ/JAVA] 백준 5300 : Fill the Rowboats (자바)

by HoonSikE 2023. 10. 21.
반응형
SMALL
문제 정보
  문제명   - Fill the Rowboats
  난이도   - 브론즈 IV
문제 번호 - 5300번

문제 링크

https://www.acmicpc.net/problem/5300

 

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


문제
Captain Jack decides to to take over a rival’s ship. He needs to send his henchmen over on rowboats that can hold 6 pirates each. You will help him count out pirates in groups of 6. The last rowboat may have fewer than 6 pirates. To make your task easier each pirate has been assigned a number from 1 to N.

입력
The input will be N, the number of pirates you need to send over on 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.

예제 입력/출력
예제 입력 예제 출력
10
 
1 2 3 4 5 6 Go! 7 8 9 10 Go!
18
 
1 2 3 4 5 6 Go! 7 8 9 10 11 12 Go! 13 14 15 16 17 18 Go!​

알고리즘 분류
● 구현

소스코드
package Lv1_Bronze;

import java.io.*;

/**
 * @author HanHoon
 * @category 구현
 * https://www.acmicpc.net/problem/5300
 */
public class BOJ_B4_5300_Fill_the_Rowboats {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder str = new StringBuilder();

        // N
        int N = Integer.parseInt(br.readLine());

        for (int n = 1; n <= N; n++){
            str.append(n + " ");
            if(n%6 == 0 || n == N)
                str.append("Go! ");
        }

        System.out.print(str);
        br.close();
    }
}

 


BaekJoon List
 

BaekJoon List

BOJ Start!! ● [BOJ] 백준 회원가입, 시작하는 법 ● [BOJ] 등급(티어) 및 Solved.AC 적용 ● [BOJ/JAVA] 백준 소스코드 제출 시 유의사항(자바) Bronze ● Bronze V  - ● Bronze IV  - ● Bronze III  -..

han-hoon.tistory.com


  

기회는 준비된 자에게 찾아온다.

 


 

반응형
LIST

댓글