๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool check(char dir,int want,int dis){
if(dir=='='){
if(dis==want) return true;
}
else if(dir=='>'){
if(dis>want) return true;
}
else if(dir=='<'){
if(dis<want) return true;
}
return false;
}
int solution(int n, vector<string> data) {
int answer = 0;
string friends="ACFJMNRT";
do{
bool flag=true;
for(int i=0; i<data.size(); i++){
char first,second,dir;
int want;
first=data[i][0];
second=data[i][2];
dir=data[i][3];
want=data[i][4]-'0';
int dis=abs(int(friends.find(first))-int(friends.find(second)))-1;
if(!check(dir,want,dis)) flag=false;
}
if(flag) answer++;
}while(next_permutation(friends.begin(),friends.end()));
return answer;
}
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์( Level 1) (0) | 2021.10.20 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ ๊ฐ ๋ฝ์์ ๋ํ๊ธฐ( Level 1) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋ ๋งต๊ฒ( Level 2) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋จ์ด๋ณํ( Level 3) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๋คํธ์ํฌ( Level 3) (0) | 2021.10.20 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ๊ดํธ ๋ณํ( Level 2, 2020 KAKAO BLIND) (0) | 2021.10.20 |
๋๊ธ