• + 1 comment

    #include

    include

    using namespace std; int main() { int n; cin>>n; int j , i = 0, cnt = 0;

            string s;
            cin>>s;
    

    for(j = 0; j < n; j++) { if(s[j] == 'U') { i = i + 1; if(i == 0) cnt++; } else if(s[j] == 'D') { i = i - 1; } }

            cout<<cnt<<endl;
    

    return 0; }