문제
Convert text to title case: the first letter of every word becomes uppercase and the remaining letters lowercase. Words are separated by single spaces.
Implement title_case(text).
Input
text: Lowercase or mixed-case words separated by single spaces.
Output
Return the title-cased text.
제약 조건
0 ≤ length ≤ 10,000 (letters and spaces)
예시
입력:
text = "hello world"
예상 출력:
expected = "Hello World"
입력:
std::string text = "hello world";
예상 출력:
std::string expected = "Hello World";
입력:
string text = "hello world";
예상 출력:
string expected = "Hello World";
설명
"hello" → "Hello" and "world" → "World".
입력:
text = "tHE qUICK fox"
예상 출력:
expected = "The Quick Fox"
입력:
std::string text = "tHE qUICK fox";
예상 출력:
std::string expected = "The Quick Fox";
입력:
string text = "tHE qUICK fox";
예상 출력:
string expected = "The Quick Fox";
설명
Remaining letters become lowercase: "The Quick Fox".
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
Split the text into words and treat each word independently.
힌트 2
Uppercase the first character and lowercase the rest, then join the words back with spaces.
힌트 3
Watch for empty input so you do not try to access a missing first character.
예상 복잡도
O(n) time, O(n) extra space
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제한 조건을 따르세요.