[백준] 5300

당당·2023년 7월 2일
0

백준

목록 보기
170/179

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

📔문제

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.


📝예제 입력 1

10

📺예제 출력 1

1 2 3 4 5 6 Go! 7 8 9 10 Go!

📝예제 입력 2

18

📺예제 출력 2

1 2 3 4 5 6 Go! 7 8 9 10 11 12 Go! 13 14 15 16 17 18 Go!

🔍출처

High School > University of Maryland High School Programming Contest > HSPC 2007 P1번


🧮알고리즘 분류

  • 구현

📃소스 코드

import java.util.Scanner;

public class Code5300 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();

        for(int i=0;i<n;i++){
            System.out.print((i+1)+" ");
            if((i+1)%6==0 || i==n-1){
                System.out.print("Go! ");
            }
        }
    }
}


📰출력 결과


📂고찰

6 다음 Go! 를 해야 하니까 만약 i+1이 6의 배수라면 뒤에 Go!를 출력해주면 된다. 또는, 마지막 원소이면 출력해주면 된다.

profile
MySQL DBA 신입 지원

0개의 댓글