본문 바로가기
백준/20001 - 25000

[백준] 23207번 : Preludes(JAVA)

by lms0806 2021. 10. 13.
728x90
반응형

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

 

23207번: Preludes

Each test case is described by one line of input having the format “note tonality”, where note is one of the 17 names for the scale notes given above, and tonality is either major or minor. All note names will be upper-case, and the two accidentals (

www.acmicpc.net

풀이

문제에 나와있는 표와 예제입력을 보고 푸시면 됩니다.

 

소스코드

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int count = 1;
		StringBuilder sb = new StringBuilder();
		String str = "";
		while((str = br.readLine()) != null) {
			StringTokenizer st = new StringTokenizer(str);
			String s = st.nextToken();
			
			sb.append("Case " + count + ": ");
			if(s.contains("b")) {
				char c = (char) (s.charAt(0) - 1);
				if(c < 'A') {
					c = 'G';
				}
				sb.append(c + "# " + st.nextToken());
			}
			else if(s.contains("#")) {
				char c = (char) (s.charAt(0) + 1);
				if(c > 'G') {
					c = 'A';
				}
				sb.append(c + "b " + st.nextToken());
			}
			else {
				sb.append("UNIQUE");
			}
			sb.append("\n");
			count++;
		}
		System.out.print(sb);
	}
}
728x90
반응형

댓글