Showing posts with label Datastructure. Show all posts
Showing posts with label Datastructure. Show all posts

Sunday, September 15, 2019

1069 - Diamonds and Sand

#include< bits/stdc++.h >
using namespace std;

int main()
{
    int n;
    string s;
    cin  >>  n;

    while(n--) {
        stack< char >st;
        int ans = 0;
        cin  >>  s;
        for(auto ch: s) {
            if(ch == '<') st.push(ch);
            else if( !st.empty() and ch == '>' ) {
                ans++;
                st.pop();
            }
        }
        cout << ans << endl;
    }

    return 0;
}