프로그래머스코딩테스트연습풀이/C++
[프로그래머스/C++] 글자 지우기
코코쵸마
2025. 2. 22. 16:47
문제
문자열 my_string과 정수 배열 indices가 주어질 때, my_string에서 indices의 원소에 해당하는 인덱스의 글자를 지우고 이어 붙인 문자열을 return 하는 solution 함수를 작성해 주세요.
솔루션
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string solution(string my_string, vector<int> indices) {
for(auto n:indices){
my_string[n] = '@';
}
for(auto n:indices){
my_string.erase(find(my_string.begin(), my_string.end(), '@'));
}
return my_string;
}
https://school.programmers.co.kr/learn/courses/30/lessons/181900
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr