URAL 1506. Columns of Numbers (analog AH)

Source: Internet
Author: User
Tags integer numbers

Title Link: http://acm.timus.ru/problem.aspx?space=1&num=1506


Every New Russian have to look through long columns of numbers for analyzing market trends and planning his investments. Psychologists assure the longer is a column of numbers, the more difficult it's to perceive it. Therefore, it's better to print numbers isn't in one long column, but in several columns so that their height would be mini Mal. Transform a given sequence of numbers to a format that's psychologically more convenient for perception. Inputthe first line contains, integers: N(1≤ N≤100), which shows how many numbers must is analyzed, and K(1≤k≤n), which is the desired number of columns. The second line contains NInteger numbers in the range from 0 to 999.OutputOutput the NNumbers given in the input in KColumns in such a by that, the number of lines is minimal and the columns has the same height with the possible exception Of the last column, which is shorter. The width of each column must is 4 symbols; The numbers must is aligned to the right edge and padded with spaces to the required width. The numbers must is given in the same order as in the input, but in columns:the first column from the top to the bottom, Then the second column from the top to the bottom, and so on. All nonempty lines must end with a line break; There must is no end spaces in the lines. It is guaranteed this solution is always exist. Sample
input Output
7 31 2 30 40 50 600 700
   1   2  30 600

Ps:

Every column runs in order!

The code is as follows:

#include <cstdio> #include <cmath>int main () {int n, K;    int a[147], b[147][147];        while (~SCANF ("%d%d", &n,&k)) {for (int i = 0; i < n; i++) {scanf ("%d", &a[i]);        } int c_num = (ceil) (n/(k*1.0));        int ss = C_num*k-n;        int LC = 0, lr = 0;            for (int i = 0; i < n; i++) {B[LR][LC] = A[i];            lr++;                if (LR >= c_num) {lc++;            LR = 0;        }} int num = 0;        int flag = 0; for (int i = 0, i < c_num; i++) {for (int j = 0; J < K; J + +) {if (j = = K                    1 && i >= c_num-ss) {flag = 1;                    printf ("\ n");                Break                } printf ("%4d", B[i][j]);            Flag = 0;        } if (!flag) printf ("\ n"); } printf ("\ n"); } return 0;}



URAL 1506. Columns of Numbers (analog AH)

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.