L1-039. 古风排版(2017初赛)

这里写图片描述
这题是for循环的运用,要注意的点是不足的地方用空格来代替。

#include <bits/stdc++.h>
using namespace std;
char a[1500];
int main()
{
    int N;
    cin>>N;
    getchar();
    cin.getline(a,1500);
    int i,j,len=0,k,m;
    len=strlen(a);
    if(len%N==0)//判断列数
        m=len/N;
    else
        m=len/N+1;
    for(i=0;i<N;i++)
    {
        for(j=0;j<m;j++)
        {
            k=m-1-j;
            if(k*N+i<len)
               cout<<a[k*N+i];  
            else 
               cout<<" "; 
        }
        cout<<endl;
    } 
    return 0;   
}

猜你喜欢

转载自blog.csdn.net/weixin_41112564/article/details/81429729