From 29a242a3c77289e96bc2aa0cd4ec6862ef809211 Mon Sep 17 00:00:00 2001 From: Udhay <72250606+Udhay-Brahmi@users.noreply.github.com> Date: Sat, 26 Dec 2020 08:11:18 +0530 Subject: [PATCH] Create Check if divisible by 10 --- Check if divisible by 10 | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Check if divisible by 10 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