Given an input line, capitalize first and last letter of each word in the given line. It\'s provided that the input line is in lowercase
belongs to collection: Interview C++ coding problems/challenges | Coding Algorithms
All Answers
total answers (1)

C++ programming
The basic algorithm is to keep track of the spaces and to capitalize the letter before space & after space. Also, the first letter and the last letter of the line should be capitalized.
Few more things that need to be kept in mind such that:
Algorithm:
For i=0:length-1 Find index of spaces in the line If index before spaces are not in hash table Insert into hash table If index after spaces are not in hash table Insert into hash tableline [index]-=32;
Inclusion of hash table in the program helps us to avoid inserting duplicate indexes. Otherwise, corner test-cases may fail.
C++ program to capitalize first and last letter of each word in a line
Output
need an explanation for this answer? contact us directly to get an explanation for this answer