Rezultati

Up. imeNalogaJezikRezultatČas oddaje
finalsolution-2018 Tabela C++ 100/100OK 13. okt '18 @ 11:03

Test Točke Porabljen spomin Porabljen čas Status
#1 20/20 4,027 MiB 0,061 s OK
#2 20/20 3,117 MiB 0,000 s OK
#3 20/20 3,125 MiB 0,004 s OK
#4 20/20 3,090 MiB 0,004 s OK
#5 20/20 3,125 MiB 0,000 s OK

Ocenjevani program (tabela.cpp):
#include <string>
#include <iostream>
#include <vector>
#include <string.h>

static std::string cols;
static std::vector<std::vector<std::string>> lines;
static std::vector<size_t> sizes;

int main() {
    int r = 0, c = 0;
    std::cin >> r;
    std::cin >> c;
    std::cin >> cols;
    sizes.resize(c);
    while ((r--) > 0) {
        std::string line;
        std::vector<std::string> row;
        std::cin >> line;
        char *cp = strtok((char *)line.c_str(), ",");
        int i = 0;
        while (cp) {
            std::string col = cp;
            row.push_back(col);
            if (col.size() > sizes[i]) sizes[i] = col.size();
            cp = strtok(NULL, ",");
            i++;
        }
        lines.push_back(row);
    }
    for (auto it = lines.begin(), end = lines.end(); it != end; it++) {
        std::vector<std::string>& line = *it;
        for (int i = 0; i < c; i++) {
            if (i) printf(" | ");
            if (cols[i] == 'L') printf("%-*s", (int)sizes[i], line[i].c_str());
            else printf("%*s", (int)sizes[i], line[i].c_str());
        }
        printf("\n");
    }
}