समस्या
Take the first letter of each word in full_name, uppercase it, and join the letters. Words are separated by one or more spaces.
Implement initials(full_name).
Input
full_name: A name made of letters and spaces.
Output
Return the initials, for example "ADL".
सीमाएँ
1 ≤ length of full_name ≤ 200; it contains at least one letter
उदाहरण
इनपुट:
full_name = "Ada Lovelace"
अपेक्षित आउटपुट:
expected = "AL"
इनपुट:
std::string full_name = "Ada Lovelace";
अपेक्षित आउटपुट:
std::string expected = "AL";
इनपुट:
string full_name = "Ada Lovelace";
अपेक्षित आउटपुट:
string expected = "AL";
व्याख्या
A from Ada and L from Lovelace: "AL".
इनपुट:
full_name = "grace brewster hopper"
अपेक्षित आउटपुट:
expected = "GBH"
इनपुट:
std::string full_name = "grace brewster hopper";
अपेक्षित आउटपुट:
std::string expected = "GBH";
इनपुट:
string full_name = "grace brewster hopper";
अपेक्षित आउटपुट:
string expected = "GBH";
व्याख्या
Extra spaces don't matter; the initials are uppercased: "GBH".
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Har word exactly ek character deta hai: uska first letter.
संकेत 2
Name traverse karte hue track karo ki spaces ke baad naya word kab start hota hai.
संकेत 3
Multiple spaces ek saath hon to dhyan do, taaki har word se sirf ek initial lo.
अपेक्षित जटिलता
समय O(n), अतिरिक्त स्थान O(1)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।