diff --git a/Check if divisible by 10 b/Check if divisible by 10 new file mode 100644 index 0000000..7caea57 --- /dev/null +++ b/Check if divisible by 10 @@ -0,0 +1,47 @@ +// { Driver Code Starts +#include +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