Educational Codeforces Round 82 (Rated for Div. 2) A. Erasing Zeroes(超简单的写法) - 图1

    题意:

    统计间隔在1中0的个数

    思路:

    超简单写法,直接利用string的find、rfind函数即可

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. int main() {
    4. //freopen("in.txt", "r", stdin);
    5. ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    6. int t; cin >> t;
    7. while (t--) {
    8. string s; cin >> s;
    9. int cnt = 0;
    10. int first = s.find('1');
    11. int last = s.rfind('1');
    12. for (int i = first; i < last; i++) if (s[i] == '0')cnt++;
    13. cout << cnt << endl;
    14. }
    15. }