1 条题解

  • 0
    @ 2025-5-28 18:02:34
    #include <iostream>
    #include <vector>
    #include <string>
    #include <algorithm>
    #include <iomanip>
    #include <cmath>
    
    using namespace std;
    
    int main() {
        int n;
        while (cin >> n) {
            vector<string> files(n);
            int max_len = 0;
            for (int i = 0; i < n; ++i) {
                cin >> ws;
                getline(cin, files[i]);
                if (files[i].length() > max_len)
                    max_len = files[i].length();
            }
    
            sort(files.begin(), files.end());
            int cols = (60 + 2) / (max_len + 2);
            if (cols == 0) cols = 1;
            int rows = (n + cols - 1) / cols;
    
            cout << string(60, '-') << endl;
            for (int r = 0; r < rows; ++r) {
                for (int c = 0; c < cols; ++c) {
                    int idx = c * rows + r;
                    if (idx < n) {
                        cout << setw(max_len) << left << files[idx];
                        if (c != cols - 1)
                            cout << "  ";
                    }
                }
                cout << endl;
            }
        }
        return 0;
    }
    • 1

    信息

    ID
    590
    时间
    1000ms
    内存
    10MiB
    难度
    6
    标签
    递交数
    1
    已通过
    1
    上传者