Skip to content

Commit

Permalink
Multiple of 3
Browse files Browse the repository at this point in the history
  • Loading branch information
maneprajakta authored Sep 30, 2020
1 parent e6aedf1 commit 5860bc0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Bit_Magic/Multipleof3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main()
{
ll t;
cin>>t;
while(t--)
{
string s;
cin>>s;
ll l=s.length();
ll i,even=0,odd=0,oe=-1;
for(i=l-1;i>=0;i--){
if(oe==-1){

if(s[i]=='1')odd+=1;
}
else {
if(s[i]=='1')even+=1;

}
oe=oe*-1;
}
if(abs(even-odd)%3==0)cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
}

0 comments on commit 5860bc0

Please sign in to comment.