이상한 문자 만들기
https://programmers.co.kr/learn/courses/30/lessons/12930
코딩테스트 연습 - 이상한 문자 만들기
문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을
programmers.co.kr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
string solution(string s) { | |
string answer = ""; | |
int index = 0; | |
char space = ' '; | |
for (char c : s) | |
{ | |
if (c == space) | |
{ | |
answer += space; | |
index = 0; | |
continue; | |
} | |
if (index % 2 == 0) | |
{ | |
answer += toupper(c); | |
} | |
else | |
{ | |
answer += tolower(c); | |
} | |
++index; | |
} | |
return answer; | |
} |
반응형
'자료구조 와 알고리즘 > 프로그래머스' 카테고리의 다른 글
K번째수 (0) | 2022.05.08 |
---|---|
두 개 뽑아서 더하기 (0) | 2022.05.08 |
자릿수 더하기 (0) | 2022.05.08 |
콜라츠 추측 (0) | 2022.05.08 |
평균 구하기 (0) | 2022.05.08 |