L1-1 古风排版 (20 分)
中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。
输入格式:
输入在第一行给出一个正整数(),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
输出格式:
按古风格式排版给定的字符串,每列个字符(除了最后一列可能不足个)。
输入样例:
4 This is a test case
输出样例:
asa T st ih e tsi ce s
#include <iostream>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
using namespace std;
char a[1005][1005];
int main(){
    int n;
    cin>>n;
    getchar();
    string s;
    getline(cin,s);
    int len=s.size();
    int m=len/n+(len%n==0?0:1);
    int cnt=0,now=m;
    memset(a,' ',sizeof(a));
    //n行m列
     while(1){
        for(int i=1;i<=n;i++){
            if(cnt==len)break;
            a[i][now] = s[cnt++];
        }
        now--;
        if(now==0)break;
     }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            printf("%c",a[i][j]);
        if(i!=n)
        cout<<endl;
    }
    return 0;
}
//先把矩阵全填成空格 然后根据规律往矩阵里填数据