URAL 1506. Columns of Numbers(模拟啊 )
来源:互联网 发布:mac开机显示客人用户 编辑:程序博客网 时间:2024/05/23 11:42
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1506
Every New Russian has to look through long columns of numbers for analyzing market trends and planning his investments. Psychologists assure that the longer is a column of numbers, the more difficult it is to perceive it. Therefore, it is better to print numbers not in one long column, but in several columns so that their height would be minimal. Transform a given sequence of numbers to a format that is psychologically more convenient for perception.
Input
The first line contains two integers: N (1 ≤ N ≤ 100), which shows how many numbers must be 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.
Output
Output the N numbers given in the input in K columns in such a way that the number of lines is minimal and the columns have the same height with the possible exception of the last column, which may be shorter. The width of each column must be 4 symbols; the numbers must be aligned to the right edge and padded with spaces to the required width. The numbers must be 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 be no end spaces in the lines. It is guaranteed that solution is always exist.
Sample
7 31 2 30 40 50 600 700
1 40 700 2 50 30 600
PS:
每列按着顺序跑一遍就好了!
代码如下:
#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;}
1 0
- URAL 1506. Columns of Numbers(模拟啊 )
- 1506. Columns of Numbers
- URAL 1120. Sum of Sequential Numbers (数学)
- URAL 1206 Sum of Digits of the Sum of Numbers
- URAL 1290. Sabotage(STL & 模拟啊)
- URAL 1893. A380(模拟啊 )
- Ural 1915 - Reconstruction of Bygones 模拟
- URAL 1319. Hotel (模拟)
- URAL 1586 Threeprime Numbers (数位DP)
- Ural 1009 K-based Numbers(DP)
- Ural 1586 Threeprime Numbers(DP)
- ural 1009. K-based Numbers(dp)
- ural 1586. Threeprime Numbers(dp)
- URAL 2031. Overturned Numbers (枚举)
- URAL 2070 Interesting Numbers(数学)
- URAL 2070 Interesting Numbers (素数枚举)
- URAL 2070 Interesting Numbers(数论)
- ural 2070 Interesting Numbers(数论基础)
- 线段树区间求最大值
- const char *与char *转换的本质
- Java学习笔记_IO
- Ubuntu 14.04 系统托盘图标 无法显示QQ 图标问题,RTX 托盘图标
- 【SICP归纳】6 副作用与环境模型
- URAL 1506. Columns of Numbers(模拟啊 )
- 【java】反射
- Poco logger 日志使用小析
- nyoj 7 街区最短路径问题
- Unity3D中写入SQL数据库抛出InvalidProgramException解决过程
- iOS-------------断点续传
- kmp 算法总结
- 【Javaweb】后台的字符串转义,入库之前记得先对字符串转义防止sql注入问题
- C++实现指定的字符串替代(华为)