Algorithm


Problem Name: beecrowd | 1069
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1069

Diamonds and Sand

By Neilor Tonin, URI Brazil

Timelimit: 1

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

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>

using namespace std;
    
int main() {
    int n, size, counter, tmp;
    string s;

    cin >> n;

    for (int i = 0; i  <  n; ++i) {
       cin >> s;
       size = s.length();
       counter = 0;
       tmp = 0;

       for (int j = 0; j  <  size; ++j) {
        if(s[j] == '<'>
          tmp++;
        if (s[j] == '>' && tmp > 0) {
            counter++;
            tmp--;
        }
       }

       cout << counter << endl;

    }

    return 0;
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
2 <..><.<..>> <<<..<......<<<<....>

Output

x
+
cmd
3 1
Advertisements

Demonstration


Previous
#1068 Beecrowd Online Judge Solution 1068 Parenthesis Balance I - Solution in C, C++, Java, Python and C#
Next
#1070 Beecrowd Online Judge Solution 1070 Six Odd Numbers - Solution in C, C++, Java, Python and C#