31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14191. B. Bit Designs a Word Processor. Programmer B. Bit decided to design itsown word processor. One of operations that the word processor should be able toperform is finding the phrase in the given text.B. Bit decided that it would be convenient for him if the word processor couldcalculate how many times the indicated phrase appears in the given text and whilesearching for the phrase would apply these rules for matching upper-case and lowercaseletters:?if the phrase contains lower-case letters only, upper and lower-case letters shouldbe considered as equivalents. For example, the phrase jonas corresponds tojonas, JONAS, Jonas, jonaS, and etc.?if there is at least one upper-case letter in the phrase, upper and lower-case lettersshould be considered as different. For example, the phrase Jonas corresponds toJonas only but not to JONAS, jonas, jonaS, and etc.Phrases can cover each other. For example, in the text AAA phrase AA appears twice.If the last symbol of text line is dash (-) it means that word is moved to the otherline. When word processor is searching for a phrase, it ignores this dash and joinsparts of word in the different lines. If the last symbol is not a dash, it is considered thatone space character is after the last symbol in the text line.Note. The same dash in the middle of the line means punctuation mark thus thewords should not be joined.Task. Write an algorithm to calculate how many times the given phrase appears inthe text under the rules above.Input. The first line of the input file contains the phrase to be searched. The lengthof the phrase does not exceed 20; it contains upper and lower-case letters.The second line of the input file contains number k (1 ≤ k ≤ 30) of text lines whilethe remaining k lines contain the text.Length of the line (number of symbols)does not exceed 80. Text contains upperand lower-case letters, spaces, punctuationmarks, and numbers.Output (one integer) must be printedto screen.Inputlittle2A littlErabbit.ExampleResult1192. Winter in The Kingdom of Fancy. One day there was a heavy snow in theKingdom of Fancy and all roads became impracticable. It was not possible to clean allthe roads quickly, so the Government decided to clean only some selected roads, suchthat there would be a connection (not necessary direct) between any two towns. Tomake this work easier and cheaper, it was decided to choose the roads to be cleaned sothat the total length of the roads would be the least.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!