https://school.programmers.co.kr/learn/courses/30/lessons/12951
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
[C++][프로그래머스][Lv2] 12951. JadenCase 문자열 만들기
❗주의할 점
1. 공백문자가 여러개 올 수 있다.
2. 공백문자 끝날 수 있다.
이 부분 예외를 생각못해서 테스트에서 막혔었다....
✅사용한 헤더파일, 함수
: #include <cctype>의 toupper() , tolower()
#include <cctype>
// 1. 대문자로 변경
char temp = 'a';
char uppderCase = toupper(temp); // A
// 2. 소문자로 변경
char temp2 = 'A';
char lowerCase = tolower(temp2); // a
✅풀이방법
#include <string>
#include <vector>
using namespace std;
string solution(string str) {
string answer = "";
string temp = "";
for(int i = 0; i <str.length(); i++)
{
// 공백이면 ?
if (str[i] == ' ')
{
// temp가 비어있을 때
if (temp.empty())
{
answer += " ";
continue;
}
// temp가 안 비어있을 때
else
{
answer += toupper(temp[0]);
for (int j = 1; j < temp.size(); j++)
answer += tolower(temp[j]);
answer += " ";
temp.clear();
}
}
else
temp += str[i];
}
// 끝났는데 temp가 안비어있으면 ? -> 마지막이 문자열로 이루어져있으면
if (!temp.empty())
{
answer += toupper(temp[0]);
for (int j = 1; j < temp.size(); j++)
answer += tolower(temp[j]);
}
return answer;
}
https://github.com/kimYouChae/C-Programmers
GitHub - kimYouChae/C-Programmers
Contribute to kimYouChae/C-Programmers development by creating an account on GitHub.
github.com
'프로그래머스' 카테고리의 다른 글
[C++][프로그래머스][Lv2] 42842. 카펫 (1) | 2024.07.18 |
---|---|
[C++][프로그래머스][Lv2] 12911. 다음 큰 숫자 (0) | 2024.07.11 |
[C++][프로그래머스][Lv2] 70129. 이진 변환 반복하기 (0) | 2024.07.08 |
[C++][프로그래머스][Lv2] 12909. 올바른 괄호 (0) | 2024.07.02 |
[C++][프로그래머스][Lv2] 12939. 최댓값과 최솟값 (0) | 2024.07.02 |