#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Remove duplicate characters from sorted array
void remove_dups(char *str) {
char *cur = str;
while(*str) {
*str = *cur;
while(*cur == *str) cur++;
str++;
}
}
int cmp(const void *a, const void *b)
{
return *(char*)a - *(char*)b;
}
int same_digit(int a, int b)
{
char A[22], B[22]; // Room for 64 bit. Increase if necessary.
char Aun[11], Bun[11]; // 10 digits
sprintf(A, "%d", a);
sprintf(B, "%d", b);
qsort(A, strlen(A), sizeof *A, cmp);
qsort(B, strlen(B), sizeof *B, cmp);
remove_dups(A);
remove_dups(B);
return !strcmp(A, B);
}
int main()
{
printf("%d\n", same_digit(1234, 4321));
printf("%d\n", same_digit(1234, 1111));
printf("%d\n", same_digit(1234, 1111342));
}