Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

mkumar 77600gmail.com Problem Statement Consider a non-empty string instr containing only lower-case alphabets and an array of strings inarr, containing a collection of words, with

mkumar 77600gmail.com Problem Statement Consider a non-empty string instr containing only lower-case alphabets and an array of strings inarr, containing a collection of words, with its elements separated by comma. There is one-to-one correspondence between the characters of instr and the words in inarr. Identify and print outstr based on the below logic: 10 For each of the unique characters in instr Identify the index firstind of its first occurrence in instr and the list of indices indexlist for the other occurrences if any

Identify the corresponding string str in inarr at index firstind If the string str is present in inarr across all the identified indices of indexlist and ONLY at these identified indices then the unique character in instr is said to have a special mapped word in inarr Add ONLY those unique character(s) having a special mapped word to outstr in their order of occurrence in instr If there is no character identified having a special mapped word, assign "NA" in upper case to outstr . . Input format: . If there is no case to outstr Input format First line contains instr Second line contains inarr with its elements separated by (',') comma Read the inputs from standard input stream Output format: Print the outstr to the standard output stream.

Explanation Sample Output Sample Input + in ondoa ac For the given input string instr,the unique characters based on their order of occurance in instr are 'd','b', 'a','c' obabbca bat ball,rat, bat, bat,car,rat le 1 For each unique character the firstind, indexlist and corresponding str are: "" &-> -> firstind = 0, indexlist = empty, str="bat" 'b' -> firstind = 1 indexlist = 3,4, str ="ball" 3 str="bat public { 'b' -> firstind = 1, indexlist = 3,4 , str ="ball" 'a' -> firstind = 2, indexlist = 6, str ="rat" to ooo ya ura 'C' -> firstind = 5, indexlist = empty, str = "car" 13 } The unique characters with special mapped word in inarr are identified as follows:

The indexlist for 'd'is empty. But public static void ma 7 is not present in inarr in all the identified Indices. Hence 'b' does not have a special mapped word in inarr Scanners - ne 9 String inputstr 18 11 System.out.pr 12 13 } The indexlist for 'a' is 6. Its stri.e., "rat", is present in inarr in all the identified indices and Danly in these indices.

Hence 'a' has a special mapped word in inarr The indexlist for 'c' is empty. Its str i.e., "car, is present in inarr only in the identified indices. Hence 'c' has a special mapped word in inarr Adding the identified 2 3 W mo NA 4 5 For the given input string instr, the unique characters based on their order of occurance in instr is 'a. E For each unique character the firstind, indexlist and corresponding str are:

'a' -> firstind = 0, Indexlist = 1, str="bat " , Here 'a' does not have a special mapped word in inarr because its str is not presnt in inarr in all the identified indices. car 3 class my Code 5. The unique characters with special mapped word in inarr are identified as follows: public stat { 6 7. * 8. *5c sto 10 11 sy 12 } The indexlist for 'd'is empty. But its str i.e.,"bat

", is not present in inarr only at the identified indices as it occurs in indices 3 and 4 in inarr. Hence 'd' does not have a special mapped word in inarr 13 } The indexlist for 'b' is 3,4. But its str i.e.,"ball, is not present in inarr in mapped 3 clas 5 6 The indexlist for 'c is empty. Its stri.e., "car", is present in inarr only in the identified indices. Hence 'c' has a special mapped word in inarr

7 8 10 11 Adding the identified unique alphabets of instr with special mapped word in inarr to outstr in their order of occurrence hn instr, outstr becomes "ac". Hence the output aa NA bat, ball For the given input string instr,

the unique characters based on their order of occurance in instr is 'a. inarr became not presnt in inarr in all the identified indices. Since none of the unique alphabets in instr has a special mapped character in inarr, assing "NA"in uppercase) to outstr. Hence the output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions