코딩공부/프로그래머스
[프로그래머스] [PCCP 모의고사 #1] 1번 - 외톨이 알파벳 c++
usingsystem
2023. 12. 19. 09:01
728x90
https://school.programmers.co.kr/learn/courses/15008/lessons/121683?language=cpp
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
소스코드
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string input_string) {
string answer = "";
for (int i = 0; i < input_string.size(); i++)
{
bool same = true;
char temp = input_string[i];
for (int j = i + 1; j < input_string.size(); j++)
{
if (temp != input_string[j])
same = false;
if (same == false && temp == input_string[j])
{
if (answer.find(input_string[j]) == -1)
answer += input_string[j];
}
}
}
if (answer == "")
answer += "N";
sort(answer.begin(), answer.end());
return answer;
}
728x90