Suppose I have two integer number 4578 and 5908.
Now I have to find the common digits for these two integers.
For the integers given above the output should be 58 (because 5 & 8 are common in both integers.)
How many ways there are to do this?
What will be the most efficient way?
You can first store the digits in two vectors and then compare each elements , if there's a match print it.
Extracting the digits is easy as well , note that the last digit could be extracted by doing mod 10 , then divide the number by 10 to remove the last digit.
So these are the hints .
Convert the two numbers to strings, then check the two strings.
1 2 3 4 5 6
string s1;
string s2;
s1 = to_string (4578); // Requires C++11
s2 = to_string (5908);
// Now iterate through the digits in s1 and see if they exist in s2