Created
August 14, 2013 06:56
-
-
Save byelims/6228608 to your computer and use it in GitHub Desktop.
From USACO Section 1.2 Palindromic Squares
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* put the base b representation of n into s: 0 is represented by "" */ | |
void | |
numbconv(char *s, int n, int b) | |
{ | |
int len; | |
if (n == 0) { | |
strcpy(s, ""); | |
return; | |
} | |
/* figure out first n-1 digits */ | |
numbconv(s, n/b, b); | |
/* add last digit */ | |
len = strlen(s); | |
s[len] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n%b]; | |
s[len+1] = '\0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment