Ultraviolet A 400-Unix ls (typographical)

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.