Array and Strings – Strings – Problem #12
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Take input a long sentence that contains an arbitrary number of words. Two words are supposed to be separated by only one blank space character. Also a valid word consists of only the ASCII characters ‘A-Z’ or ‘a-z’ and nothing else. However the sentence that you will be taking as input may not follow this rule, i.e there may be more than one blank spaces between two words as well the words themselves may contain invalid characters. Your task is to refine this invalid input to get the correct valid string in place, i.e that you CANNOT use any additional array to perform this operation, you have to process within the same input array with perhaps one or two additional character variables. Print the final valid string as well. You can assume that any sequence of characters ‘A-Z’ or ‘a-z’ forms a valid word although it may not exist in the dictionary [No need to consider full stop also at the end]. You are NOT allowed to use any in-built string functions. Example: Input: Acceler56ation is def9ine%d as r34@at56e 78of chang4e of ve2@locity Output: Acceleration is defined as rate of change of velocity