Feb 5, 2010 at 1:39pm UTC
please if i want to enter like 27 and want to count how many numbers from 0 to 27 except the like number e.g. 11 , 22 , etc.
can any one help me in write this
Feb 5, 2010 at 2:05pm UTC
Is the input limited to the numbers 0-99?
How can you programmatically determine if the tens digit equals the ones digit?
Feb 5, 2010 at 2:15pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
bool areAllDigitsEquals(int number)
{
std::stringstream ss;
ss << number;
std::string str = ss.str();
if (str.size() <= 1)
{
return false ;
}
int prev = str[0];
for (size_t i = 1, count = str.size(); i < count; ++i)
{
if (prev != str[i])
{
return false ;
}
prev = str[i];
}
return true ;
}
Last edited on Feb 5, 2010 at 2:20pm UTC
Feb 5, 2010 at 3:05pm UTC
i need help again
i need the parameter of the problem as this
int count(int n)
Feb 5, 2010 at 3:38pm UTC
1 2 3 4 5 6 7
int count(int n) {
int total = n;
for (int i = 0; i <= n; ++i) {
total -= areAllDigitsEquals(i);
};
return total;
}
You can just need a
for
loop to keep calling Denis' code.
Last edited on Feb 5, 2010 at 3:38pm UTC
Feb 5, 2010 at 4:48pm UTC
Supposing that the input is limited to 2 digits, I will add to jsmith's questions (hints).
For a number n, what is n / 10?
For a number n, what is n % 10?
Feb 5, 2010 at 4:55pm UTC
@moorecm, I would have posted the same if not for:
makes it a bit harder if the size is anywhere between 0 and that using modulo
Last edited on Feb 5, 2010 at 4:57pm UTC