A roll of raffle tickets is printed as one long strip containing lowercase letters, star stamps (*), and perforation marks (|). Perforation marks always come in pairs: the 1st and 2nd | on the strip bound one ticket, the 3rd and 4th bound the next ticket, and so on -- the strip is guaranteed to contain an even number of perforation marks. Occasionally a star stamp is printed inside a ticket's perforated boundary as a printing flaw and should be ignored; only the star stamps printed in the surrounding margin, outside every ticket's boundary, should be counted. Given the strip, count its margin star stamps.
A single line containing the strip s.
Print a single integer: the number of * characters in s that do not lie between some pair of perforation marks.
*, and |.| characters in s is even.Example 1
Input
ab*cd|ef*gh|ij*kl
Expected
2
Explanation
The first and second '|' enclose one ticket, "ef*gh", whose star stamp is a printing flaw and is not counted. The remaining stars sit in the margins before and after the ticket, in "ab*cd" and "ij*kl" -- one star each -- giving a total of 2.
Example 2
Input
*a|bb*|cc|dd**|*e*
Expected
3
Explanation
The four '|' marks bound two tickets: "bb*" (1 star) and "dd**" (2 stars), whose 3 combined stars are ignored. The margins outside those tickets are "*a" (1 star), "cc" (0 stars), and "*e*" (2 stars), giving a total of 1 + 0 + 2 = 3.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →