牛客(多校3): Clam and Fish

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        int e=0,f=0;
        int n;
        cin>>n;
        string a;
        cin>>a;
        for(int i = 0;i < n;i++){
            if(a[i]=='2'||a[i]=='3')    f++;
            if(a[i]=='0'&&e!=0)    e--;f++;
            if(a[i]=='1')    e++;
        }
        cout<<f+e/2<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_46144237/article/details/107561160
今日推荐