Given a string name, we have to find the initials of the name
Input : prabhat kumar singh Output : P K S We take the first letter of all words and print in capital letter. Input : Jude Law Output : J L Input : abhishek kumar singh Output : A K S
1) Print first character in capital.
2) Traverse rest of the string and print every character after space in capital letter.
P K S
Another possible solution is given as follows:
P K S
The complexity of this code will be less than O(w) where w is number of words in sentence, which can be little better than number of characters in String.
This code is contributed by Anuj Khasgiwala
We can also use strtok() function in C/C++ to achieve this.
This article is contributed by Prabhat kumar singh. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- A Program to check if strings are rotations of each other or not
- Write a program to print all permutations of a given string
- Given a string, find its first non-repeating character
- Write a program to reverse an array or string
- Find the smallest window in a string containing all characters of another string
- Given a number, find the next smallest palindrome
- Program to validate an IP address
- Find if a string is interleaved of two other strings | DP-33
- Find the first non-repeating character from a stream of characters
- Find Excel column name from a given column number
- Given a sorted dictionary of an alien language, find order of characters
- Find if an array of strings can be chained to form a circle | Set 1
- Given two strings, find if first string is a subsequence of second
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Find all distinct palindromic sub-strings of a given string
- Find maximum depth of nested parenthesis in a string
- Function to find Number of customers who could not get a computer
- Find the longest substring with k unique characters in a given string
- Find the maximum subarray XOR in a given array
- Find the most frequent digit without using array/string