由于昨天正好在练习stl中的stack所以遇见c题就尝试用栈来写,欢迎指正

#include<bits/stdc++.h>

//#include using namespace std;

int main() {

string s;
cin>>s;
int n=s.length(),i;
if(n<=1) cout<<0;
else
{
    int count=0;
   stack<char>stk;
    for(i=0;i<n;i++)//使用栈来模拟题中叙述的过程
    {
        if(stk.empty()) stk.push(s[i]);
        else
        {
            if(stk.top()<='z'&&stk.top()>='a')
            {
                if(s[i]>='A'&&s[i]<='Z')
                {
                    s[i]=' ';
                    count++;
                    stk.push(s[i]);
                }
                else if(s[i]>='a'&&s[i]<='z')
                {
                    stk.push(s[i]);
                }
            }
            else if(stk.top()<='Z'&&stk.top()>='A')
            {
                if(s[i]>='A'&&s[i]<='Z')
                {
                    s[i]=' ';
                    count++;
                    stk.push(s[i]);
                }
                else if(s[i]>='a'&&s[i]<='z')
                {
                    stk.push(s[i]);
                }
            }
            else if(stk.top()==' ')
            {
                stk.push(s[i]);
            }
        }
    }
    cout<<count;
}

}