https://school.programmers.co.kr/learn/courses/15008/lessons/121683?language=cpp
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <set>
using namespace std;
string solution(string input) {
string answer = "";
set<char> s;
set<char> resSet;
for (int i = 0; i < input.size(); i++) {
if (i == input.size() - 1 || input[i] != input[i + 1]) {
if (s.find(input[i]) != s.end())
resSet.insert(input[i]);
else
s.insert(input[i]);
}
}
auto it = resSet.begin();
while (it != resSet.end())
answer += *it++;
if (answer == "")
return ("N");
return answer;
}
set 이름을 set으로 했다가 오류 났었다 조심~
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 PCCP모의고사 1회 3번 유전법칙 c++ (0) | 2023.09.08 |
---|---|
프로그래머스 PCCP모의고사 1회 2번 체육대회 c++ (0) | 2023.09.06 |
프로그래머스 무인도 여행 c++ (1) | 2023.09.02 |
프로그래머스 쿼드압축 후 개수 세기 c++ (0) | 2023.09.02 |
프로그래머스 삼각 달팽이 c++ (0) | 2023.09.02 |