[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;
    }
}

相关文章:

  • 2021-11-24
  • 2021-05-02
  • 2021-04-24
  • 2021-11-16
  • 2021-06-04
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2021-07-24
  • 2021-07-21
相关资源
相似解决方案