Array and Strings – Strings – Problem #11
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
You might have observed queues in railway reservation counters. In a queue when the first person leaves the queue, the second person becomes the first member of the new queue. Write a C program to input n characters into a character array of size n. Consider the original queue to be this character array of size n. In each iteration, compute the number of vowels that are present within the current iteration’s queue (say this number be ‘k’) and print all the elements of the queue by skipping the first k elements of the queue. This queue that you have printed becomes your new queue for the next iteration and continue this process until there are no more elements in the queue or there are no vowels remaining in the current queue being considered. For printing the new queue you do not need to perform any deletion or array resizing operation. Rather always keep track of the beginning index of the latest queue for each iteration and advance the index accordingly at the end of iteration. You may use only one array to implement the queue. Example: (Please take the input and display the output as shown) Input: Original queue: a, y, u, g, h, i, e, k, l [NOTE: While taking input the character array one by one use scanf(“<space> %c”,&ar[i]) within the loop, where i is the index and ar is the character array. GIVE ONE SPACE BE- TWEEN THE opening quote and the ‘%c’ within the scanf() ] Output: (You would need to print the iteration number as well as shown) ——-Iteration-1——— New queue: h, i, e, k, l [Reason: In the original queue there are 4 vowels, a, u, i and e. Hence k=4. Thus display the queue from after the first 4 elements of the original queue and the displayed queue becomes your new queue for the next iteration] ——-Iteration-2——— New queue: e, k, l [Reason: Same as above, now considering the new queue from the previous iteration] ——-Iteration-3——— New queue: k, l [END here, no more vowels]