URI Online Judge Solution 1069 Diamonds and Sand using Python Programming Language.
John is working in a diamond mine, trying to extract the highest number of diamond "<>". He must exclude all sand particles found "." in this process and after a diamond can be extracted, new diamonds can be formed. If he has as an input. <... << .. >> ....> .... >>>. three diamonds are formed. The first is taken from <..> resulting. <... <> ....> .... >>>. The second diamond is then removed, leaving. <.......> .... >>>. The third diamond is then removed, leaving at the end ..... >>>. without the possibility of extracting new diamonds.
Input
Read an integer N that is the number of test cases. Then follows N lines each up to 1000 characters, including "<" ,">" and "."
Output
You must print the amount of diamonds that can be extrated in each test case.
Input Sample | Output Sample |
2
<..><.<..>> <<<..<......<<<<....> |
3
1 |
Solution using Python :
T = int(input())
while T>0:
Str = input()
Count = 0
Sign = 0
for i in Str:
if (i == "<"):
Sign += 1
if (i == ">" and Sign > 0):
Count += 1
Sign -= 1
print(Count)
T-=1
Comments
Post a Comment