Micro and Binary Strings

QUESTION

Micro’s wife Mini gave him a bag having N strings of length N. All the strings are binary i.e. made up of 1’s and 0’s only. All the strings in the bag can be generated by a string S by simply performing right rotations N times. \n\nFor example if S is \”101\”, then the strings in the bag will be \”110\”, \”011\”, \”101\”. Now Mini wants to know the number of ways of selecting one string from the bag with an odd decimal equivalent. Micro got very confused by all this, so he asked for your help.\n\nInput:\n\nThe first line consist of an integer T denoting the number of test cases.\nFirst line of each test case consists of an integer denoting N.\nSecond line of each test case consists of a binary string denoting S.\n\nOuptut:\nPrint the answer for each test case in a new line.\n\nConstraints:\n1<=T<=100\n1<=N<=10^5.

ANSWER

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int q,x;
    char a[100000];
    cin>>q;
    while(q--)
    {
        int count=0;
        cin>>x;
        cin>>a;
        
        for(int i=0;i<x;i++)
        {
            if(a[i]=='1')
            ++count;
        }
        cout<<count<<'\n';
        
        
    }
    return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.