UVa-Unix is

Source: Internet
Author: User
Tags first string

Test instructions: Give n strings, order them in dictionary order, and then output them according to the rules.

= = = Study purple book, the topic meaning is very clear, the number of columns and the number of rows at the beginning of the first look at the wood to understand Ah ah Ah

Number of columns: that is (60-m)/(m+2) +1; that is, to subtract the last column first, count the average number of columns, and then add the last column

Number of lines: can be used in purple Book (n-1)/cols+1, also available ceil function

The coordinates are then counted as the first string, which is the top-to-bottom of the arrows in the graph.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <math.h>6 using namespacestd;7 8 Const intMaxcol= -;9 Const intmaxn= -+5;Ten stringFILENAMES[MAXN]; One  A voidPrintConst string&s,intLenCharextra) - { -cout<<s; the      for(intI=0; I<len-s.length (); i++) -cout<<Extra; - } -  + intMain () - { +     intN; A      while(cin>>N) at     { -         intm=-5; -          for(intI=0; i<n;i++)  -         { -Cin>>Filenames[i]; -M=max (M, (int) filenames[i].length ()); in         } -         intcols,rows; tocols= (maxcol-m)/(m+2)+1; +Rows=ceil ((1.0) *n/cols); -      theSort (filenames,filenames+n); *Print"", -,'-'); $printf"\ n");Panax Notoginseng          -          for(intI=0; i<rows;i++)//Number of rows the         { +              for(intj=0; j<cols;j++)//Number of columns A             { the                 intidx=j*rows+i; +                 if(idx<N) -Print (filenames[idx],j==cols-1? m:m+2,' '); $             } $printf"\ n"); -         }                 -     } the}
View Code

UVa-Unix is

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.