프로그래머스
[c++/프로그래머스] LV2 JadenCase 문자열 만들기
돈 많은 백수가 되고싶다
2023. 5. 7. 01:08
https://school.programmers.co.kr/learn/courses/30/lessons/12951
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string solution(string s) {
//check가 true인 상태일 때 (공백 다음에 나오는 문자)
int i = 0;
bool check = true; //맨 처음 나오는 단어에 대응
while (s[i]) {
//공백일 경우 넘어감
if (s[i] == ' ') {
check = true;
i++;
continue;
}
else
{
//공백이 아닌 문자를 만났을 경우
//1. 첫번째 문자
if (check) {
s[i] = toupper(s[i]);
check = false;
}
//2. 첫번째가 아닌 문자
else
{
s[i] = tolower(s[i]);
check = false;
}
i++;
}
}
return s;
}
// 출력값 확인을 위해
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str;
getline(cin, str);
cout<<solution(str);
}