C++:: 프로그래머스 < 이상한 문자 만들기 >

jahlee·2023년 8월 6일
0

프로그래머스_Lv.1

목록 보기
61/75
post-thumbnail

sstream을 사용하여 풀다가 애를 먹었는데, 그냥 for문을 하는 편이 예외처리도 쉽고 편하다.

#include <string>
#include <vector>
using namespace std;

string solution(string s) {
    int idx = 0;
    for(int i=0; i<s.size(); i++) {
        if (s[i] == ' ') {
            idx=0;
            continue; 
        }
        if (idx%2) {
            s[i] = tolower(s[i]);
        } else {
            s[i] = toupper(s[i]);
        }
        idx++;
    }
    return s;
}

0개의 댓글