UVA Solution 400 - Unix ls - Solution in C, C++ | Volume 4 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Sunday, May 7, 2017

UVA Solution 400 - Unix ls - Solution in C, C++ | Volume 4

UVA Solution 400 - Unix ls - Solution in C, C++ | Volume 4



URI Online Judge Solution  | Data structures
URI Main Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=6&page=show_problem&problem=341

Problem Name: URI Problem  400 - Unix ls
Problem Number : URI Problem   400 - Unix ls  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

UVA Solution 400 - Unix ls - Solution in C, C++ | Volume 4

URI Solution  400 - Unix ls  Code in CPP:


#include <iostream>
#include <cstdio>
#include <iomanip>
#include <set>
using namespace std;

int main() {
    int n;
    while(cin >> n) {
        string s, d[n];
        set<string> in;
        int width = 0;
        for(int i = 0; i < n; i++) {
            cin >> s;
            in.insert(s);
            if(s.length() > width)
                width = s.length();
        }
        puts("------------------------------------------------------------");
        width += 2;
        if(width >= 60) width = 60;
        int idx = 0, m = 60/width;
        for(set<string>::iterator i = in.begin(); i != in.end(); i++) {
            d[idx++] = *i;
        }
        int l = n/m + (n%m != 0);
        for(int i = 0; i < l; i++) {
            for(int j = 0; i+j < n; j += l) {
                cout << left << setw(width) << d[i+j];
            }
            cout << endl;
        }
    }
    return 0;
}

No comments:

Post a Comment