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