ZJ a565: 2.p&q的邂逅

這題雖然是stack題
不過只有p需要被丟進stack裡等q出現
所以開個變數模擬一下就好了
以下為code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define AC ios::sync_with_stdio(0),cin.tie(0);

int main()
{
AC
ll n;
while(n--)
{
string s;
cin>>s;
ll p=0,q=0,l=s.size();
for(ll i=0;i<l;i++)
{
if(s[i]=='p') p++;
else if(s[i]=='q'&&p>q) q++;
}
cout<<q<<'\n';
}
}

留言

這個網誌中的熱門文章

TIOJ 1080 . A.逆序數對 (BIT解法)

ZJ d718: Waiting In Line

AtCoder Educational DP Contest E - Knapsack 2