문제
영소문자로 이루어진 문자열 my_string과 영소문자 1글자로 이루어진 문자열 alp가 매개변수로 주어질 때, my_string에서 alp에 해당하는 모든 글자를 대문자로 바꾼 문자열을 return 하는 solution 함수를 작성해 주세요.
솔루션
#include <string>
#include <vector>
#include <cctype>
using namespace std;
string solution(string my_string, string alp) {
string answer = "";
for(int i = 0; i < my_string.size(); i++){
if(my_string[i] == alp[0]){
answer += toupper(alp[0]);
}
else{
answer += my_string[i];
}
}
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/181873
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
'프로그래머스코딩테스트연습풀이 > C++' 카테고리의 다른 글
[프로그래머스/C++] 배열에서 문자열 대소문자 변환하기 (0) | 2025.02.14 |
---|---|
[프로그래머스/C++] A 강조하기 (0) | 2025.02.14 |
[프로그래머스/C++] 공백으로 구분하기 2 (0) | 2025.02.14 |
[프로그래머스/C++] 문자열 바꿔서 찾기 (0) | 2025.02.14 |
[프로그래머스/C++] rny_string (0) | 2025.02.14 |