 # STRLBP - Editorial

Practice

Contest

Author: Praveen Dhinwa

Tester: Jingbo Shang

Editorialist: Utkarsh Saxena

### PROBLEM

Given a binary string of length 8. Make the string circular.
Count number of places where adjacent bits are different. Print “Uniform” if this count \le 2

### EXPLANATION

Since this problem was a cakewalk, it is quite straightforward to code.
There is quite less to explain apart from giving some observations.

#### Bruteforce C++

``````for(int i=0;i<8;++i)
count += s[i] != s[(i+1)&7];
``````

#### Bruteforce Python

``````for i in range(8):
count += s[i] != s[i-1]
``````

#### Random observations

To have count=0 the string must have 8\space 0's or 8\space 1's.

It is not possible to have count=1.

To have count = 2, the string must have exactly one 1 or exactly one 0.

So for this problem the total number of 1 in the string can be 0, 1, 7, 8.

### AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.

**include<iostream.h>
void main() { int s,c=0; for(int i=0;i<8;i++) { if (s[i]!=s[i+1]) { c=c+1 } } if(c<=2) { cout<<“uniform”;} else cout<<“non-uniform”; }

#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t–)
{
string s;
cin>>s;
int x=unique(s.begin(),s.end())-s.begin();
if(x<=3)
{
cout<<“uniform\n”;
}
else
{
cout<<“non-uniform\n”;
}
}
return 0;
}

``````#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

ll t;
cin >> t;
while(t--) {
string s;
cin >> s;
int counter = 0;
for(int i = 0; i < s.size() - 1; i++) {
if(s[i] == '1' && s[i + 1] == '0' || (s[i] == '0' && s[i + 1] == '1')) {
counter++;
}
}
if(counter <= 2) {
cout << "uniform" << endl;
} else {
cout << "non-uniform" << endl;
}
}
}
``````

#include<stdio.h>
int main()
{
int l = 8;

``````int t,rem;
scanf("%d",&t);
while(t--)
{   int count = 0;
int count1 = 0;
char s;
scanf("%s",s);
for(int i=0; i<l; i++)
{
rem = s[i] % 48;
if(rem == 0)
{
count++;
}
else
{
count1++;
}
}
if((count > count1)||(count < count1))
{
printf("uniform\n");
}
else
{
printf("non-uniform\n");
}
}
return 0;
``````

}