HINT??
how to approach this problem??
Finding cb numbers
Hello @akb.tech17,
Approach:
-
check for all sub-strings of the given string of digits, starting from the all strings of length 1 and then gradually checking for the strings of increasing size:
1.1. check if the sub-string is CB number: for this, create a function
1.1.1. if sub-string is 1 or 0 return false.
1.1.2. if sub-string is any of the {2,3,5,7,11,13,17,19,23,29}, then return true.
1.1.3. if sub-string is divisible by any of the {2,3,5,7,11,13,17,19,23,29}, then return false.
1.1.4. return false
1.2. now if it is a substring:
1.2.1. call a function that marks the index as visited for indexes which are part of that CB number.
1.3. increment the count for CB number. -
Print the count
Hope, this would help.
Give a like if you are satisfied.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
https://ide.codingblocks.com/s/188992 sir plz check my code , i have to implement that if two CB numbers are sharing a part of on string i have to eliminate one of them,how to do that
hey @akb.tech17 we need to first check every substring of length 1 followed by every substring of length 2, you are not doing that.
Take a bool array of the same size and everytime you find a cb number mark it in the bool array and only accept a number if every digit of that number is free
Also since the number can be large you need to make isCBnumber work on long long as well
Please refer to this code for more
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.