您的位置:首页 > 其它

L1-039. 古风排版

2018-03-19 18:54 344 查看

L1-039. 古风排版

时间限制400 ms
内存限制65536 kB
代码长度限制8000 B
判题程序Standard作者陈越
中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。输入格式:输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。输出格式:按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)输入样例:
4
This is a test case
输出样例:
asa T
st ih
e tsi
ce s
提交代码

坑就在于后面的换行符

# include <iostream>
# include <algorithm>
# include <set>
# include <map>
# include <vector>
# include <queue>
# include <numeric>
# include <string>
# include <cstring>
# include <iomanip> 
# include <cstdio>
//# include <bits/stdc++.h>
using namespace std;  
int main()  
{  
    int n,m;  
    char s[1001],a[101][1001];  
    scanf("%d",&n);  
    getchar();  
    gets(s);  
    int l=strlen(s),t=0;  
 //   m=(l+n-1)/n;///和下面两行一样的效果  
    m=l/n; 
    if(l%n!=0) m++; 
    for(int j=m-1;j>=0;j--)  
    {  
        for(int i=0;i<n;i++)  
        {  
            if(t<l) a[i][j]=s[t++];  
            else a[i][j]=' ';///不足的补空格  
        }  
    }  
//4个一组
    for(int j=0;j<n;j++)  
    {  
        for(int i=0;i<m;i++)  
            cout << a[j][i];
        printf("\n");  
    }  
    return 0;  
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: