csct3434
[level 2] 단체사진 찍기 - 1835 본문
#include <bits/stdc++.h>
using namespace std;
bool checkCondition(string friends, string cond) {
char op = cond[3];
int requiredDistance = cond[4] - '0';
int distance = abs(int(friends.find(cond[0]) - friends.find(cond[2]))) - 1;
if(op == '=') {
if(distance != requiredDistance) {
return false;
}
} else if(op == '<') {
if(!(distance < requiredDistance)) {
return false;
}
} else {
if(!(distance > requiredDistance)) {
return false;
}
}
return true;
}
bool isPossible(string friends, vector<string> data) {
for(auto cond : data) {
if(!checkCondition(friends, cond)) {
return false;
}
}
return true;
}
int solution(int n, vector<string> data) {
string friends = "ACFJMNRT";
int answer = 0;
do {
if(isPossible(friends, data)) {
answer++;
}
} while(next_permutation(friends.begin(), friends.end()));
return answer;
}
'프로그래머스' 카테고리의 다른 글
[level 2] 3 x n 타일링 - 12902 (0) | 2024.02.28 |
---|---|
[level 2] 2 x n 타일링 - 12900 (0) | 2024.02.28 |
[level 2] 124 나라의 숫자 - 12899 (0) | 2024.02.28 |
[level 2] 게임 맵 최단거리 - 1844 (0) | 2024.02.28 |
[level 2] 카카오프렌즈 컬러링북 - 1829 (0) | 2024.02.28 |