Skip to content

Instantly share code, notes, and snippets.

@sashabaranov
Created October 28, 2012 09:04
Show Gist options
  • Save sashabaranov/3968104 to your computer and use it in GitHub Desktop.
Save sashabaranov/3968104 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define BUF_SIZE 256
int main()
{
char A[BUF_SIZE], B[BUF_SIZE], C[BUF_SIZE];
scanf("%s %s %s", &A, &B , &C);
int base;
long int c_A, c_B, c_C; // converted
for(base = 2; base < 36; base++)
{
c_A = strtol(&A, NULL, base);
c_B = strtol(&B, NULL, base);
c_C = strtol(&C, NULL, base);
if((c_A + c_B) == c_C && (c_A != 0 && c_B != 0 && c_C != 0))
{
printf("%d", base);
return 0;
}
}
printf("-1");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment