eolymp
bolt
Try our new interface for solving problems
Problems

Polly Wants a Cracker

Polly Wants a Cracker

\includegraphics{https://static.e-olymp.com/content/db/dbe2baeaf53204e988d24b83cdc22eb60f675f5b.jpg} In the pirate society, each pirate captain is obligated to obtain a pet. This pet should be at the side (or on the shoulder) of a pirate captain at all times, especially during conversations with good doers who wish to challenge the captain's evil ways. Greedbeard is the infamous and feared captain of the pirate ship Greatlooter. His pet is the infamous and feared parrot known as Polly. As a parrot, Polly likes to mimic the conversations he overhears. Unfortunately, Polly is not very good at mimicking the sentences he hears. For this reason, Greedbeard has taken it upon himself to assist Polly as he learns to speak the human tongue. Greedbeard noted that Polly is able to speak whole sentences, but often makes one or more of the three following mistakes: \begin{enumerate} \item Polly mixes up the sentence by placing words in the wrong order. E.g. instead of saying "\textit{polly wants a cracker}", Polly will say "\textit{polly cracker a wants}"; \item Polly forgets some words in a sentence. E.g. instead of saying "\textit{polly wants a cracker}", Polly will say "\textit{polly a cracker}"; \item Finally, Polly mixes up, adds or removes consonants and vowels^1 in his words. So instead of saying "\textit{polly wants a cracker}", Polly will say "\textit{polly wantsu a trackets}". \end{enumerate} Note that Polly never mimics the same word twice in a sentence. The captain always knows the original sentence that Polly is trying to mimic. Captain Greedbeard is not interested in the first two mistakes. However, mixing up letters or adding/removing letters from a word makes his blood boil. Therefore, each time Polly makes mistakes in a sentence by mixing up letters, the captain will take away one cracker from his lunch, for each letter he mixes up. The number of crackers that the captain removes per word, is the minimum number of edits needed to transform the spoken word into the word that Polly was trying to say. An edit is de ned as either an insertion, deletion or substitution of a single letter. It is not always clear how words in the mimicked sentence correspond to words in the original sentence. Greedbeard assumes the mimicked words are matched with the original words in such a way that the total number of mistakes is minimal. For instance, if Polly should have said: "\textit{polly wants a cracker}" and says: "\textit{polly crackets wantsu}", the captain will remove \textbf{3} crackers from his lunch. These are \textbf{2} crackers for messing up the word "\textit{cracker}" and \textbf{1} cracker for adding a letter to the word "\textit{wants}". He does not care that the word "\textit{a}" is missing, or that words are spoken in the wrong order. _______________ ^1 - Read: mixes up, adds or removes letters. \InputFile The fi rst line of the input contains a single number: the number of test cases to follow. Each test case has the following format: \begin{itemize} \item A line containing a single string (\textbf{1} ≤ \textbf{length} ≤ \textbf{1000}), representing the sentence that Polly is trying to mimic; \item A line containing a single string (\textbf{1} ≤ \textbf{length} ≤ \textbf{1000}), the sentence that Polly has spoken. \end{itemize} Additional notes: \begin{itemize} \item The sentence Polly mimics consists of one to eight words. \item A word is a sequence of lowercase letters. Each word ends with a space, or with the end of the sentence. \item A sentence does not contain a sequence of multiple spaces. \end{itemize} \OutputFile For every test case in the input, the output should contain one integer on a single line: the number of crackers that Greedbeard will withhold from Polly's lunch.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
polly wants a cracker
polly crackets wantsu
pretty polly
petty polli
pieces of eight
eight of pieces
Output example #1
3
2
0
Source 2011 Benelux Algorithm Programming Contest, Preliminaries, Problem D