크게 어렵지 않은 문제다.
string의 index가 아니라 단어별로 홀/짝을 구분하는것만 신경 써주면 된다.
#include <string>
using namespace std;
string solution(string s) {
int cnt = 1;
for (int i = 0, cnt = 1; i < s.size(); i++, cnt++)
{
if (s[i] != ' ')
{
if (cnt % 2 == 0)
s[i] = tolower(s[i]);
else
s[i] = toupper(s[i]);
}
else
cnt = 0;
}
return s;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 자연수 뒤집어 배열로 만들기 (0) | 2022.04.27 |
|---|---|
| [프로그래머스] (C++) LV1 자릿수 더하기 (0) | 2022.04.27 |
| [프로그래머스] (C++) LV1 약수의 합 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 시저 암호 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 문자열을 정수로 바꾸기 (0) | 2022.04.26 |