빠켱이

프로그래머스 가운데 글자 가져오기[C++] 본문

알고리즘/프로그래머스 알고리즘

프로그래머스 가운데 글자 가져오기[C++]

빠켱이 2021. 4. 9. 14:33
#include <string>
#include <vector>

using namespace std;

string solution(string s) {
    string answer = "";
    if(s.length() % 2 == 0){    //짝수이면
        answer += s[s.length() / 2 - 1];
        answer += s[s.length() / 2];
    }
    else{
        answer += s[s.length() / 2];
    }
    return answer;
}
Comments