슈콩

[SWEA] 색상환 본문

Algorithms/SWEA

[SWEA] 색상환

shukong 2025. 11. 18. 20:55

 

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AZROsPgqE88DFAWB

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String[] color = {"red", "orange", "yellow", "green", "blue", "purple"};
		HashMap<String,Integer> hm = new HashMap<>();
		for(int i=0;i<6;i++) {
			hm.put(color[i], i);
		}
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			st = new StringTokenizer(br.readLine());
			String a = st.nextToken();
			String b = st.nextToken();
			String result = "X";
			if(a.equals(b)) result = "E";
			else {
				int idxA = hm.get(a);
				int idxB = hm.get(b);
				if((idxA+1)%6==idxB || (idxA-1+6)%6==idxB) result = "A";
				else if((idxA+3)%6==idxB) result = "C";
			}
			System.out.println(result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 몬스터 사냥  (0) 2025.11.18
[SWEA] 평범한 숫자  (0) 2025.11.18
[SWEA] 로봇 언어  (0) 2025.11.18
[SWEA] 승률 비교하기  (0) 2025.11.18
[SWEA] 세상의 모든 팰린드롬 2  (0) 2025.11.18