By Victor Jatobá and Ariane Machado, USP Brazil
The Eachians are very concerned about the text that has received from neighboring planet. They suspect that there is a pattern in the number represented by a word position in the text. These positions together, they say, represents a key to deactivate a bomb that is about to explode the EACH planet.
You were then summoned to developing a program that receive a text and a set of words and return the first position of each word that is present in the text.
Constraints:
Word: can contain only lowercase letters of the alphabet ('a'-'z').
Text: can contain only lowercase letters of the alphabet ('a'-'z') separated by one whitespace. Text contains no line break ('\n') and no special characters.
The size of the words will be never greater than the size of the text.
Position: You should consider that the first position of the text should be position 0 (zero). Thus, in a text with 50 characters, the last position will be the 49.
You should only search for the exactly word. For example, the word SHIP is different from FRIENDSHIP.
The input need be, exactly:
The first line: The text, that contains N characters (50 <= N <= 10.000).
The second line: The M amount of the words that must be read (1 <= M <= 128).
The third line: The words separated by a whitespaces. Each word must be 2 minimal character and maximum of 50.
For each word, the program must print the position of the first letter present in the text. Mind that the words can be repeated in the text. In this instance, the positions must be printed one in front of other, separated with whitespaces. If the text doesn’t contain the word, return -1 (the number minus one).
Input Samples | Output Samples |
see a bear sell stock see a bull buy stock bid stock bid stock hear the bell stop 3 bear bid hear |
6 43 53 63 |
lorem ipsum dolor sit amet meis illum nec at summo cetero et usu adhuc justo tacimates cum et sint pericula mei eu pri ipsum eruditi periculis an no usu graecis explicari has animal sententiae in ut oportere suscipiantur mea ex est ullum quaestio in sit eius tibique no dolore numquam qui sed malorum persius utroque te ei sed omittam dissentias quaerendum ipsum altera vocent at cum facilisis iracundia sea ea mel tollit eripuit ex ne mei discere albucius sit tation convenire interesset at est te modus augue ei tempor assueverit eam ius causae definiebas at te wisi vituperata eos quem feugait vulputate mel et eum ut dicat ornatus pro cu prima deleniti patrioque ex mel ridens doctus mel consul volumus noluisse te mel oblique noluisse an te vis errem consulatu theophrastus est ne atomorum intellegam et mei scripta admodum has cu tollit primis essent exerci equidem vix te his ut sonet elaboraret qui at dicam epicurei et vel saepe instructior in soluta percipitur est quo reque voluptatum utfacilis tibique sapientem qui ut quo scripta voluptaria ad mea at possit nusquam mandamus duis facer legimus te sea id sale meis atqui nec scripta antiopam qui te nominavi mnesarchum incorrupte ut his qui ei putant impedit facilis partem nullam elaboraret vix id id probatus omittantur pro eum in ornatus repudiandae id qui alterum honestatis disputando errem graeco audiam vim ne 1 ipsum |
6 119 357 |