Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A ninja word is a word which hides in a sentence: it will appear continuously, but must be broken up by one or more spaces.

image text in transcribedimage text in transcribed

image text in transcribed

A ninja word is a word which hides in a sentence: it will appear continuously, but must be broken up by one or more spaces. For example, the word "star" is a ninja word in the phrase "best artist", but is NOT a ninja word in the phrase "twinkle twinkle little star". (Ninja words must be hidden, and thus always contain spaces). Ninja words and the sentences they appear in will always be case-insensitive. In addition, sentences may contain ninja stars (denoted with an asterisk" *"). Ninja stars can be any character, including a space. Given a list of possible ninja words, and a target sentence, return the score of the ninja words that appear in the sentence, according to the rules below. Inputs targetwords: A list of possible ninja words - e.g., ["Sun", "Moon", "Star., "Planet"] sentence: A target sentence which may contain ninja words - Sentences will contain ASCli characters Aa-Zz, spaces, and asterisks - e.g., "All the stars under the sky twinkle in slo mo on a clear night" Output Determine the score of the uncovered ninja words according to the following rules: - 1 polne for every ninja word found 1 additional point for each ninja star contained in the word Determine the score of the uncovered ninja words according to the following rules: - 1 point for every ninja word found - 1 additional point for each ninja star contained in the word - "nin ja" 1 point "**n ja" 3 points - Each ninja word should only be counted once per sentence. If a ninja word appears multiple times, only count the instance which gives the most points Example 1 - targetWords: ["Sun". Moon" "Star", "Planet"] - sentence: "All the stars unden the sky twvinkle in slo mo on a clear night" - Analysis: The target sentence contains 2 ninja words: o "Sun", in "stars under": - "Maon" in 'slo mo onil - The mord "Star" is inthe sentence, butiti is Nor a sinja word, because it is not split up by a space. - Each ninja word isworth 1 point fol a total of 2 . - Return 2 Example 2 - targetwords: [Water" "Sea", Beach" "Lake, "Shells"] - sentence: "All the stars under the sky twinkle in slo mo on a clear night" - Analysis: The target sentence contains 2 ninja words: - "Sun", in "stars under" - "Moon", in "slo mo on" - The word "Star" is in the sentence, but it is NOT a ninja word, because it is not split up by a space. - Each ninja word is worth 1 point for a total of 2. - Return 2 Example 2 - targetwords: ["Water". "Sea", "Beach", "Lake", "Shell""] - sentence: "She sells she*lls on the shore for two sand dollar* each" - Analysis: The first ninja star lets us find the word "shells", when we replace "t*" with a space. The second ninja star allows us to find 2 additional ninja words. If we replace the * withan "s" "dollars each" contains "sea". If we replace the * with a "b", "dollarb each" contains "beach". - Each ninja word we ve found has exactly one star in it, meaning each word is worth 2 points, for a total of 6 points. - Found words: She*l/s > She 1/5 "Shells" Dollark each Dollarb each "Beach" Dollar* each Dollars each "Sea" - Return 6

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

Database And Expert Systems Applications Dexa 2022 Workshops 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 In Computer And Information Science 33

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Alfred Taudes ,Atif Mashkoor ,Johannes Sametinger ,Jorge Martinez-Gil ,Florian Sobieczky ,Lukas Fischer ,Rudolf Ramler ,Maqbool Khan ,Gerald Czech

1st Edition

3031143426, 978-3031143427

More Books

Students also viewed these Databases questions