#include #include #include

using namespace std;

int main() { int N; string str; cin >> N; cin.ignore(); getline(cin, str);

int len = str.length();
int rows = len / N + (len % N == 0 ? 0 : 1);

vector<vector<char>> grid(rows, vector<char>(N, ' '));

int idx = 0;
for (int j = N - 1; j >= 0; j--) {
    for (int i = 0; i < rows; i++) {
        if (idx < len) {
            grid[i][j] = str[idx++];
        }
    }
}

for (int i = 0; i < rows; i++) {
    for (int j = 0; j < N; j++) {
        cout << grid[i][j];
    }
    cout << endl;
}

return 0;
c++写程序:中国的古人写文字是从右向左竖向排版的。本题就请你编写程序把一段文字按古风排版。输入格式:输入在第一行给出一个正整数N100是每一列的字符数。第二行给出一个长度不超过1000的非空字符串以回车结束。输出格式:按古风格式排版给定的字符串每列N个字符除了最后一列可能不足N个。输入样例:4This is a test case输出样例:asa Tst ihe tsi ce s

原文地址: https://www.cveoy.top/t/topic/hQtu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录