File tree Expand file tree Collapse file tree 2 files changed +90
-59
lines changed
Expand file tree Collapse file tree 2 files changed +90
-59
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ #include < bits/stdc++.h>
6+ using namespace std ;
7+ typedef long long ll;
8+
9+
10+ int solve (){
11+ string s;
12+ cin>>s;
13+ int n=s.size ();
14+ int count=0 ;
15+
16+ int oneZero=0 ,zeroOne=0 ;
17+ for (int i=1 ;i<n;i++){
18+ if (s[i-1 ]==' 0' && s[i]==' 1' ){
19+ zeroOne++;
20+ }
21+ else if (s[i-1 ]==' 1' && s[i]==' 0' ){
22+ oneZero++;
23+ }
24+ }
25+ for (int i=0 ;i<n;i++){
26+ int tempZeroOne=zeroOne,tempOneZero=oneZero;
27+ if (i-1 >=0 ){
28+ if (s[i-1 ]==' 1' ){
29+ // 11 -> 10
30+ if (s[i]==' 1' ){
31+ tempOneZero++;
32+ }
33+ // 10 -> 11
34+ else {
35+ tempOneZero--;
36+ }
37+ }
38+ else {
39+ // 01 -> 00
40+ if (s[i] == ' 1' )
41+ {
42+ tempZeroOne--;
43+ }
44+ // 00 -> 01
45+ else
46+ {
47+ tempZeroOne++;
48+ }
49+ }
50+ }
51+ if (i+1 <n){
52+ if (s[i]==' 1' ){
53+ // 11 -> 01
54+ if (s[i+1 ]==' 1' ){
55+ tempZeroOne++;
56+ }
57+ // 10 -> 00
58+ else {
59+ tempOneZero--;
60+ }
61+ }
62+ else {
63+ // 01 -> 11
64+ if (s[i + 1 ] == ' 1' )
65+ {
66+ tempZeroOne--;
67+ }
68+ // 00 -> 10
69+ else
70+ {
71+ tempOneZero++;
72+ }
73+ }
74+ }
75+ if (tempZeroOne==tempOneZero){
76+ count++;
77+ }
78+ }
79+ cout<<count<<endl;
80+ return 0 ;
81+ }
82+ int main ()
83+ {
84+ int testCase=1 ;
85+ cin>>testCase;
86+ while (testCase--){
87+ solve ();
88+ }
89+ return 0 ;
90+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments