Cross the Bridge
Submissions: 433   Accuracy:


  Difficulty: Easy   Marks: 2

RA-ONE had kidnapped a lady and kept it in his castle . G-ONE got to know about this and he went there to save her. He found that in order to save her he needed to cross the bridge. The bridge was very high above the ground level and had had some planks missing. The length of the bridge was L metres. The bridge had some planks missing and were represented by . while planks on the bridge were represented by $.
The problem was that G-ONE could jump only those number of planks which he had practiced for otherwise he need to go and practice 1 day to perfect that steps of jump .
Find how many days it will take G-ONE to cross the bridge. In the input, the Bridge is described as a string P of '$'s and '.'s. A '$' represents a plank, while a '.' represents the absence of a plank. The string, when read from left to right, describes the bridge to RA-ONE hideout.
If the days exceed 7 print "cannot save" else print "saved" along with the number of days in which the lady will be saved.
The first line consists of a single integer T, the number of testcases.
Each of the next T lines consist of the string P for that case.
For each case, output whether lady can be saved or not. If yes, then also print the number of days.
1 ≤ T ≤ 100
1 ≤ |P| ≤ 1,000,0 (104)
P will consist of only the characters $ and .
The first and the last characters of P will be $

saved 1
saved 2
saved 0
saved 3
For 2nd test case 1 day is required to practice for 2 dots. Then next time 3 dots are encountered so 1 more day to practice. Then since 1 dot is there one can easily do that because G-ONE has mastered for 3 dots.

** For More Input/Output Examples Use 'Expected Output' option **

Author: Ayush Saluja

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.