Only Three!
InterviewTime limit1sMemory limit256 MB
Count how many length-3 windows of a digit string are strictly increasing and are not extended to a run of four or more consecutive digits.
- Level
Easy3 of 10
- Topics
- String, Implementation, Simulation, Array
- Solved
- No attempts yet
Problem
Given a string of digits, each between 0 and 9 inclusive, print how many times three consecutive digits appear. If four or more digits are consecutive, none of their parts count, and the three consecutive digits must be in increasing order.
Input
The first line gives the string . ()
Output
Print the number of times three consecutive digits appear.
Hint
Consider 23123856782467392. Here 123 and 567 are consecutive digits. However, 5678 has 8 attached after 567, so four digits are consecutive; excluding it, only 123 is the answer.