Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions Check if divisible by 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// { Driver Code Starts
#include <bits/stdc++.h>
using namespace std;

// } Driver Code Ends





class Solution {
public:
int isDivisibleBy10(string bin) {
int n =bin.length();
if(bin[n-1]=='1')return 0;
int sum=0;
for(int i=n-2;i>=0;i--){
if(bin[i]=='1'){
int posFromRight = n-i-1;
if (posFromRight % 4 == 1)
sum = sum + 2;
else if (posFromRight % 4 == 2)
sum = sum + 4;
else if (posFromRight % 4 == 3)
sum = sum + 8;
else if (posFromRight % 4 == 0)
sum = sum + 6;
}
}
return (sum%10==0)?1:0;
}
};


// { Driver Code Starts.
int main() {

int t;
cin >> t;
while (t--) {
string bin;
cin >> bin;
Solution ob;
cout << ob.isDivisibleBy10(bin);
cout << endl;
}
} // } Driver Code Ends