Tuesday, August 2, 2016

UVA 400 - Unix ls Solution

Unknown
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    while (scanf("%d",&n)!=EOF)
    {
        getchar();
        string s[n];
        for (int i=0;i<n;i++) cin>>s[i];
        sort (s,s+n);
        int len[n],max=0;
        for (int i=0;i<n;i++)
        {
            len[i]=s[i].size();
            if (max<len[i]) max=len[i];
        }
        int col=62/(max+2);
        int row=n/col+(n%col>0);
        for (int i=0;i<60;i++) printf("-");
        printf("\n");
        for (int i=0;i<row;i++)
        {
          for (int j=i;j<n;)
          {
            cout<<s[j];
            int l=max-len[j];
            while (l--) printf(" ");
            j+=row;
            if (j<n) printf("  ");
          }
          printf("\n");
        }
    }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,