-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path374A.cpp
More file actions
41 lines (37 loc) · 671 Bytes
/
374A.cpp
File metadata and controls
41 lines (37 loc) · 671 Bytes
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
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
int arr[150];
int main(){
int n;
string s;
cin>>n;
cin>>s;
int cnt = 0;
int fl = 0;
int len = 0;
for(int i=0;i<n;i++){
if(s[i]=='B'&&fl==1){
len++;
}
else if(s[i]=='B'&&fl==0){
cnt++;
len = 1;
fl = 1;
}
else if(fl==1){
arr[cnt] = len;
len = 0;
fl = 0;
}
}
if(fl==1&&len>0){
arr[cnt] = len;
}
cout<<cnt<<endl;
for(int i=1;i<=cnt;i++){
if(i==1) cout<<arr[i];
else cout<<" "<<arr[i];
}
if(cnt>0)
cout<<endl;
}