Usaco 1.2.4palindromicsquares: blind play 1! For cervical spine 1! Question :...... Note that the question is 1 ~ 300 the square of these numbers is converted into the corresponding hexadecimal number,! The first number in each row is represented by the required input !!!!!!!! I did not understand the test case at the beginning. Detail generation
USACO 1.2.4 Palindromic Squares: blind play 1! For cervical spine 1! Question :...... Note that the question is 1 ~ 300 the square of these numbers is converted into the corresponding hexadecimal number,! The first number in each row is represented by the required input !!!!!!!! I did not understand the test case at the beginning. Detail generation
USACO 1.2.4 Palindromic Squares
Blind beat + 1! For cervical spine + 1!
Question :...... Note that the question is 1 ~ 300 the square of these numbers is converted into the corresponding hexadecimal number,! The first number in each row is represented by the required input !!!!!!!! I did not understand the test case at the beginning.
Details + code:
/* ID: 15257142 LANG: c task: palsquare */# include
# Include
# Include
Int n; int trans (int num, char B [20]) {int k, g; k =-1; while (num> 0) {k ++; g = num % n; if (g> 9) B [k] = G-10 + 'a'; elseb [k] = g-0 + '0 '; num = num/n;} B [k + 1] = '\ 0'; return k;} int transnum (int num, int n, char e [20]) {int k; k =-1; while (num> 0) {k ++; if (num % n> 9) e [k] = num % N-10 + 'a'; elsee [k] = num % n + '0'; num = num/n;} return k ;} int main () {// It's too long. It won't be like this at the beginning if the question is clear ...... Freopen ("palsquare. in "," r ", stdin); freopen (" palsquare. out "," w ", stdout); int I, j, k, g, t, f; char c [20], d [20], B [20], e [20]; scanf ("% d", & n); for (I = 1; I <= 300; I ++) {k = I * I; g = trans (k, B); for (j = 0; j <= g/2; j ++) c [j] = B [j]; c [j] = '\ 0'; if (g % 2 = 1) f = g/2 + 1; elsef = g/2; for (j = g; j> = f; j --) d [g-j] = B [j]; d [g-j] = '\ 0'; if (strcmp (c, d) = 0) {k = transnum (I, n, e); for (j = k; j> = 0; j --) printf ("% c ", e [j]); printf (""); printf ("% s \ n", B) ;}} fclose (stdin); fclose (stdout); return 0 ;}