Coding Test Study - 10주차 +α

Checking·2021년 6월 29일
0

Coding Test Study

목록 보기
12/22

Level 2

단체사진 찍기

1차

#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

bool CanPosition(string pos, vector<string> data) {
    for (int i=0; i<data.size(); i++) {
        int diff = abs(int(pos.find(data[i][0]) - pos.find(data[i][2]))) - 1;
        int condition = data[i][4] - '0';
        
        switch(data[i][3]) {
            case '=':
                if (diff != condition) {
                    return false;
                }
                break;
            case '>':
                if (diff <= condition) {
                    return false;
                }
                break;
            case '<':
                if (diff >= condition) {
                    return false;
                }
                break;
        }
    }

    return true;
}

int solution(int n, vector<string> data) {
    int answer = 0;
    string pos = "ACFJMNRT";
    
    do {
        if (CanPosition(pos, data)) {
            answer++;
        }
    } while (next_permutation(pos.begin(), pos.end()));
    
    return answer;
}
정확성  테스트
  테스트 1 〉	통과 (2704.51ms, 4.04MB)

채점 결과
  정확성: 100.0
  합계: 100.0 / 100.0
profile
(ง ᐖ)ว

0개의 댓글