[CF1303A] Erasing Zeroes

Solution

找到边界然后循环扫一遍数个数即可

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

int n;
const int N = 1005;
char s[N];

signed main() {
    int t;
    cin>>t;
    while(t--) {
        cin>>s+1;
        n=strlen(s+1);
        int p=1,q=n;
        while(s[p]=='0' && p<=n) ++p;
        while(s[q]=='0' && q) --q;
        int cnt=0;
        for(int i=p;i<=q;i++) if(s[i]=='0') ++cnt;
        cout<<cnt<<endl;
    }
}
原文地址:https://www.cnblogs.com/mollnn/p/12345813.html