#include #include #include int z; unsigned long To10(char *s) { unsigned long vysl; char *s1; if (z == 1) { if (*s == '0') return(0); else return(strlen(s)); } else { vysl=0; s1=s; while (*s1) { vysl*=z; if (isdigit(*s1)) vysl+=*s1-'0'; else vysl+=*s1-'A'+10; s1++; } return(vysl); } } void ToZ(unsigned long x, char *s) { int i,ind; long ii,zb; int a, b; char cc; if (z == 1) { if (!x) strcpy(s,"0"); else { strcpy(s,"1"); for (ii=1;ii= 0 && zb <= 9) *(s+ind)=zb+'0'; else *(s+ind)=zb+'A'-10; ind++; x/=z; } *(s+ind)='\0'; a=0; b=strlen(s)-1; while (a < b) { cc=*(s+a); *(s+a)=*(s+b); *(s+b)=cc; a++; b--; } } } int main(void) { char s[3030],*s1,*s2; char sv[3030]; unsigned long x,y; scanf("%d", &z); while (z) { while (getchar() != '\n') ; fgets(s,3000,stdin); s[strlen(s)-1]='\0'; s1=s; s2=strchr(s,' '); *s2='\0'; s2++; x=To10(s1); y=To10(s2); /* printf("%lu + %lu\n", x, y); */ ToZ(x+y,sv); printf("%s + %s = %s\n", s1, s2, sv); scanf("%d", &z); } return(0); }