The question goes like this: build the recursive function bool isEven(int a, int b) that figures out if there's an even/odd amount of occurrences of b in a.
for example:
isEven(9545, 4) returns false
isEven(9545, 5) returns true
I'm wondering what is the edge case for this problem, I thought of disassembling the number into group of subsets of b and check every subset recursively if it's even/odd but I got stuck with building this program.
void main() {
int n, d;
cin >> n >> d;
if(isEven(n, d))
cout << "Yes" << endl;
else
cout << "No" << endl;;
}
bool isEven(int n, int d)
{
int dgtsnum = digitsInNum(n);
if (dgtsnum == 1)
{
returnfalse;
}
else
{
for (int i = 1; 2 * i < dgtsnum; i++)
powerset(2 * i, n);
}
}
int powerset(int i, int j)
{
}
int digitsInNum(int n)
{
int i = 1;
int j = 10;
while (n / ((int)j) >= 1)
{
i++;
j *= 10;
}
return i;
}