As you have already answered about how to solve it with character strings, I explain how to solve it by managing only numbers.
To do this by playing with numbers, the logarithm in base 10 is a great ally. The grace of this logarithm is that it allows you to calculate the number of digits of a number:
#include <cmath>
#include <iostream>
int main()
{
int numero;
std::cin >> numero;
std::cout << "El numero " << numero
<< " tiene " << static_cast<int>(std::log10(numero))+1
<< " digitos\n";
}
This can be used to extract the initial digits with some ease. For this, knowing the number of digits to filter, it is enough to calculate the power in corresponding base 10 and make a division:
numero: 371234
digitos: 6
necesito quedarme con los dos primeros, luego
digitos = digitos - 2 -> digitos = 4
divisor = 10^digitos = 10000
numero / divisor = 37 <<--- Lo que estamos buscando
To keep the last two, just calculate the rest of 100
numero: 1234582
numero / 100 = 12345
numero % 100 = 82 <<--- Lo que estamos buscando
And finally, to know if the number has the digits 3 and 7 we must discard the two extremes ... the last digit is easy to discard because it is enough to divide the number by 10. To go through the number we continue dividing between 10 and we keep the rest, watching that the number is greater than or equal to 10 to avoid processing the most significant digit:
numero: 147419638
numero / 10 = 14741963 <<--- Digito menos significativo fuera
numero % 10 = 3 <<--- El numero tiene un tres
numero / 10 = 1474196
numero % 10 = 6
numero / 10 = 147419
numero % 10 = 9
numero / 10 = 14741
numero % 10 = 1
numero / 10 = 1474
numero % 10 = 4
numero / 10 = 147
numero % 10 = 7 <<--- El numero tiene un siete
numero / 10 = 14
numero % 10 = 4
numero / 10 = 1 <<--- Menor de 10, paramos para ignorar el digito más significativo
Said with code:
int digitos = static_cast<int>(std::log10(numero))+1;
int divisor = std::pow(10,digitos-2);
int primerosDigitos = numero / divisor;
bool cumple = ( primerosDigitos == 37 ); // Comprobamos si numero = 37XXXXX
int ultimosDigitos = numero % 100;
cumple |= ( ultimosDigitos == 82 ); // Comprobamos si numero = XXXX82
// Comprobamos si el numero tiene 3 y 7 y no estan en los extremos
bool tiene3 = false;
bool tiene7 = false;
while( numero>= 10 )
{
numero/= 10;
int digito = numero% 10;
tiene3 |= (digito == 3);
tiene7 |= (digito == 7);
}
cumple |= (tiene3 && tiene7);
std::cout << (cumple ? " Verdadero\n" : " Falso\n");