ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1506. Columns of Numbers

My AC solution
Posted by Homka 30 Jan 2012 17:09
C++, 0.015 sec, 196 Kb

#include <iostream>
using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int m=n/k + ((n%k==0) ? 0:1);

    int * A=new int [m*k];
    for (int i=0;i<n;i++)
    {
        cin>>A[i];
    }
    for (int i=n;i<m*k;i++)
        A[i]=-1;

    for (int i=0;i<m;i++)
    {
        for (int j=0;j<k;j++)
        {
            int h=j*m+i;
            if (A[h]<0)
                cout<<"    ";
            if (A[h]>-1 && A[h]<10)
                cout<<"   "<<A[h];
            if (A[h]>9 && A[h]<100)
                cout<<"  "<<A[h];
            if (A[h]>99 && A[h]<1000)
                cout<<" "<<A[h];
        }
        cout<<endl;
    }

    return 0;
}

Waiting of comments
My AC solution
Posted by Sunnat 4 Dec 2012 17:50
C, 0.015 sec, 112 kb
main()
{
    short n,k,a[101],i,j;
    scanf("%d %d",&n,&k);
    k=(n+k-1)/k;
    for(i=0;i<n;i++)scanf("%i",&a[i]);
    for(j=0;j<k;puts(""),j++)
        for(i=j;i<n;i+=k)
           printf("%4d",a[i]);
}