题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1506
| input | output |
|---|---|
7 3 1 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;
}
URAL 1506. Columns of Numbers(模拟啊 )
原文地址:http://blog.csdn.net/u012860063/article/details/44699251