정말 오랜만에 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은 풀 수 있나봐