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

题意:

统计间隔在1中0的个数

思路:

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

#include<bits/stdc++.h>
using namespace std;
int main() {
	//freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		string s; cin >> s;
		int cnt = 0;
		int first = s.find('1');
		int last = s.rfind('1');
		for (int i = first; i < last; i++) if (s[i] == '0')cnt++;
		cout << cnt << endl;
	}
}

The desire of his soul is the prophecy of his fate
你灵魂的欲望,是你命运的先知。

原文地址:https://www.cnblogs.com/RioTian/p/13586885.html