L1-039 古风排版

题目:

上代码:

#include <iostream>
using namespace std;
int main() {
    int n,col;
    string s;
    cin>>n;
    getline(cin,s);
    getline(cin,s);
    int len=s.length();
    if(len%n!=0) 
        col=len/n+1;
    else
        col=len/n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<col;j++){
            if((col-j-1)*n+i<len)
                cout<<s[(col-j-1)*n+i];
            else
                cout<<" ";
        }
        cout<<endl;    
    }
    return 0;
}

这次运气又比较好。不过还是归功于要在纸上画出来,不然光脑子想容易忘掉很多细节,最后还检查半天检查不出来。写几个数字花不了多久,思路也更清晰看着也直观。

原文地址:https://www.cnblogs.com/littleLittleTiger/p/10374919.html