Skip to content

Commit

Permalink
Merge pull request #598 from harshil2712/patch-6
Browse files Browse the repository at this point in the history
Create myBinaryMultipleOf3.cpp
  • Loading branch information
iamjaspreetsingh authored Oct 26, 2018
2 parents 6e40991 + 2c6941e commit cff0342
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions SOLUTIONS/myBinaryMultipleOf3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <iostream>
#include <math.h>
#include <cstring>

using namespace std;

int main() {

int qtd, count = 0, len, exponent;
cin >> qtd;

for(int i = 0; i < qtd; i++) {
char binary[100];
cin >> binary;

len = strlen(binary);
for (int i = len; i >= 0; i--) {
if(binary[i-1] == '1') {
exponent = len - i;
count += pow(2, exponent);
}
}

if (count % 3 == 0){
cout << "1" << endl;
} else {
cout << "0" << endl;
}

count = 0;
}

return 0;
}

0 comments on commit cff0342

Please sign in to comment.