문제 링크입니다: https://school.programmers.co.kr/learn/courses/30/lessons/118666
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <map> | |
using namespace std; | |
const int MAX = 26; | |
int alpha[MAX]; | |
map<int, vector<char>> idx2types; | |
void init() | |
{ | |
idx2types[1] = { 'R', 'T' }; | |
idx2types[2] = { 'C', 'F' }; | |
idx2types[3] = { 'J', 'M' }; | |
idx2types[4] = { 'A', 'N' }; | |
} | |
string solution(vector<string> survey, vector<int> choices) { | |
init(); | |
for (int i = 0; i < survey.size(); i++) | |
{ | |
if (choices[i] < 4) | |
{ | |
alpha[survey[i][0] - 'A'] += 4 - choices[i]; | |
} | |
else if (choices[i] > 4) | |
{ | |
alpha[survey[i][1] - 'A'] += abs(4 - choices[i]); | |
} | |
} | |
string answer = ""; | |
for (int i = 1; i <= 4; i++) | |
{ | |
char a = idx2types[i][0]; | |
char b = idx2types[i][1]; | |
if (alpha[a - 'A'] >= alpha[b - 'A']) | |
{ | |
answer += a; | |
} | |
else | |
{ | |
answer += b; | |
} | |
} | |
return answer; | |
} |

개발환경: Programmers IDE
지적, 조언, 질문 환영합니다! 질문 남겨주세요~
반응형
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] 코딩 테스트 공부 (0) | 2022.08.26 |
---|---|
[Programmers] 두 큐 합 같게 만들기 (0) | 2022.08.24 |
[Programmers] 블록 이동하기 (0) | 2022.08.15 |
[Programmers] 매칭 점수 (0) | 2022.08.15 |
[Programmers] 외벽 점검 (0) | 2022.08.09 |