문제: 문자열 my_string이 매개변수로 주어집니다. my_string을 거꾸로 뒤집은 문자열을 return하도록 solution 함수를 완성해주세요.
코딩
#include <string>
#include <vector>
using namespace std;
string solution(string my_string) {
string answer = "";
int j = 0;
string cpy_string;
for(int i = my_string.size()-1; i>=0; i--) {
cpy_string[j] = my_string[i];
answer.push_back(cpy_string[j++]);
}
return answer;
}
출처: https://school.programmers.co.kr/learn/courses/30/lessons/120822
'밥벌이 > 코딩테스트' 카테고리의 다른 글
프로그래머스 짝수홀수 개수 (8/100) (0) | 2022.12.12 |
---|---|
프로그래머스 점의 위치 구하기 (7/100) (0) | 2022.12.12 |
프로그래머스 배열 원소 길이(5/100) (0) | 2022.12.12 |
프로그래머스 피자 나눠 먹기(나누기) (4/100) (0) | 2022.12.12 |
프로그래머스 범위기반 for문 (3/100) (0) | 2022.12.05 |