TOPIC

5% answer , why?

Roddas Cabral asked 1 year ago

include include include

int n_digitos(int); int *split_number(int);

int main(void) { long int a; scanf("%ld",&a); while(a--) { long int m,n; scanf("%ld%ld",&m,&n);

    int *array_m = split_number(m);
    int *array_n = split_number(n);
    int flag = 0;

    if(n_digitos(n) <= n_digitos(m))
    {
        int size = n_digitos(n);
        int contador;
        for(contador = 0; contador < size;contador++)
        {
            if(array_n[contador] == array_m[abs(n_digitos(m) - size) + contador])
                flag = 1;
            else
                flag = 0;
        }

    }
    (flag) ? printf("encaixa\n") : printf("nao encaixa\n");
    free(array_n);
    free(array_m);
}

return EXIT_SUCCESS;

}

int n_digitos(int numero) { int ret = 1; while(numero/=10) ret++; return ret; }

int split_number(int number) { int q = n_digitos(number); int array = (int *)calloc(q,sizeof(int)); int size = 0; while(number > 0) { int digit = number%10; array[q - (++size)] = digit; number /= 10; } return array; }

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.