This question mainly uses the integer division truncation technique. For example, when calculating the number of rows and the output, determine whether it is the last column. [Cpp] # include <stdio. h> # include <stdlib. h> # include <string. h> int cmp (const void * _ a, const void * _ B) {char * a = (char *) _ a; char * B = (char *) _ B; return strcmp (a, B);} // String Based on len Length, not enough space to fill void print (char st [], int len) {int tmp = len-strlen (st); printf ("% s", st); while (tmp --) printf ("");} int main () {int n; char s [2, 105] [65]; while (scanf ("% d", & n )! = EOF) {int lMax, c, r; lMax = c = r = 0; for (int I = 0; I <n; I ++) {scanf ("% s", s [I]); int tmp = strlen (s [I]); if (tmp> lMax) lMax = tmp ;} c = 62/(lMax + 2); // calculate the number of columns r = (n + c-1)/c; // calculate the number of rows qsort (s, n, sizeof (s [0]), cmp); printf ("------------------------------------------------------------ \ n"); for (int I = 0; I <r; I ++) {for (int j = 0; j <c; j ++) {int tmp = j * r + I; if (tmp> = n) continue; if (tmp> = (int) (n-1)/r) * r) // if the last column is print (s [tmp], lMax ); else print (s [tmp], lMax + 2);} printf ("\ n") ;}} return 0 ;}