[C++] SWEA 23003. 색상환

멋진감자·2025년 3월 20일
0

알고리즘

목록 보기
113/117
post-thumbnail

🌽 문제

🥕 입출력

🥔 풀이

정말 오랜만에 swea 문제를 풀려고 창을 켰다.
이렇게 노가다로 푸는 게 맞는지 궁금해서 다른 사람 코드를 좀 열어봤다.
문제가 의도했을 것 같은 다른 분이 작성한 풀이는 아래와 같다.

먼저 key-value 형태의 컨테이너 arr
red부터 purple까지 1~6의 숫자를 저장한다.
두 색상을 입력받은 뒤, arr[색1] == arr[색2]E를 출력한다.
abs(arr[색1] - arr[색2]) == 3이면 C를 출력한다.
abs(arr[색1] - arr[색2] == 1 or 5이면 A를 출력한다.
else X를 출력한다.

🥬 코드

#include <iostream>
#include <string>
using namespace std;

int main() {
	int t;
	cin >> t;
	string c1, c2;
	for (int i = 1; i <= t; i++) {
		cin >> c1 >> c2;
		if (c1 == c2) cout << "E\n";
		else if (c1 == "red") {
			if (c2 == "orange" || c2 == "purple") cout << "A\n";
			else if (c2 == "green") cout << "C\n";
			else cout << "X\n";
		}
		else if (c1 == "orange") {
			if (c2 == "red" || c2 == "yellow") cout << "A\n";
			else if (c2 == "blue") cout << "C\n";
			else cout << "X\n";
		}
		else if (c1 == "yellow") {
			if (c2 == "orange" || c2 == "green") cout << "A\n";
			else if (c2 == "purple") cout << "C\n";
			else cout << "X\n";
		}
		else if (c1 == "green") {
			if (c2 == "yellow" || c2 == "blue") cout << "A\n";
			else if (c2 == "red") cout << "C\n";
			else cout << "X\n";
		}
		else if (c1 == "blue") {
			if (c2 == "green" || c2 == "purple") cout << "A\n";
			else if (c2 == "orange") cout << "C\n";
			else cout << "X\n";
		}
		else {
			if (c2 == "blue" || c2 == "red") cout << "A\n";
			else if (c2 == "yellow") cout << "C\n";
			else cout << "X\n";
		}
	}
	return 0;
}

🥜 채점

나 D3은 풀 수 있나봐

profile
난멋져

0개의 댓글

관련 채용 정보