आसान 0 हल किए गए 0% स्वीकृति

Title Case

Capitalize the first letter of every word.

आप क्या सीखेंगे

  • Change the case of single characters
  • Process each word of a sentence
  • Join words back into one string

समस्या

अनुवाद दिखाएँ

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)

उदाहरण

उदाहरण 1
इनपुट:
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".

उदाहरण 2
इनपुट:
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।