티스토리 뷰

728x90

 

 

 

 

 

1384번 : 메시지 

 

1384번: 메시지

그룹 번호를 "Group 1"과 같이 출력함으로써 출력을 시작합니다. 그 다음 줄부터 누가(A) 누구(B)에게 나쁜 말을 했는지 "A was nasty about B"로 한 줄씩 출력합니다. 나쁜 말이 여러 개라면, 입력받은 순

www.acmicpc.net

 

 

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;
 
public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int idx = 1;
        while (true) {
 
            int N = Integer.parseInt(br.readLine());
            if (N == 0)
                break;
            
            StringBuilder sb = new StringBuilder();
 
            sb.append("Group " + idx+"\n");
 
            String list[][] = new String[N][N];
 
            for (int i = 0; i < N; i++) {
                String str[] = br.readLine().split(" ");
                list[i] = str;
            }
 
 
            int chk_R = 0;
            int cnt = 0;
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
 
                    if (list[i][j].equals("N")) {
 
                        chk_R = i - j;
                        if (chk_R < 0)
                            chk_R += N;
 
                        sb.append(list[chk_R][0+ " was nasty about " + list[i][0+ "\n");
                        cnt++;
                    }
                }
            }
 
            if (cnt == 0) {
                sb.append("Nobody was nasty"+"\n");
            }
            
            System.out.println(sb);
            idx++;
        }
        
        br.close();
    }
}
cs

 

 

 

결과

 

 

'코딩 > 자바 백준' 카테고리의 다른 글

백준 1925 삼각형 (JAVA)  (0) 2021.07.21
백준 1357 뒤집힌 덧셈 (JAVA)  (0) 2021.07.06
백준 1408 24 (JAVA)  (0) 2021.06.29
백준 1769 3의 배수 (JAVA)  (0) 2021.06.27
백준 1568 새 (JAVA)  (0) 2021.06.27
댓글