Codeforces Round 944 (Div. 4) D. Binary Cut

Codeforces Round 944 (Div. 4)

D. Binary Cut

遇到 ‘10’ 分割一次,‘01’ 分割 n-1(n为’01’出现次数)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// By SnowDream
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+10;
string s;
int ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--)
{
cin >> s;
ans=1;
if(s.size()<=1)
{
cout << ans << "\n";
continue;
}
for(int i=1;i<s.size();++i)
{
if(s[i-1]=='1'&&s[i]=='0')
{
ans++;
}
}
cout << ans << "\n";
}
return 0;
}

Codeforces Round 944 (Div. 4) D. Binary Cut
http://snowdreamxue.github.io/2024/10/21/Codeforces Round 944 (Div. 4)/D. Binary Cut/
Author
SnowDream
Posted on
October 21, 2024
Licensed under