L1-039 古风排版 (20 分)


L1-039古风排版(20分)

中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。

输入格式:

输入在第一行给出一个正整数N(<),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。

输出格式:

按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。

输入样例:

4
This is a test case


 1 //#include <bits/stdc++.h>
 2 //#include <cstdio>
 3 //#include <iostream>
 4 #include <stdio.h>
 5 #include <math.h>
 6 #include <string.h>
 7 #define ll long long 
 8 #define  P  pair<int,int>
 9 int n;
10 char s[1200],p[1200][1200];
11 int main()
12 {
13     scanf("%d",&n);
14     getchar();
15     gets(s);//用gets的话 stdio.h
16     int l = strlen(s);//string.h 
17     int cnt  = 0;
18 //      printf("%d\n",strlen(s));    This is a test case  :19
19  int  m = ceil(l*1.0/n);
20  for(int j= m-1;j>=0;j--){
21      for(int i=0;i<n;i++){
22     
23          p[i][j]=s[cnt++];
24      //    printf("%c\n",p[i][j]);
25          if(cnt>l) p[i][j] = ' '; //改一下就可以了 
26      }     
27  }
28  for(int i= 0;i<n;i++){
29      for(int j= 0;j<m;j++){
30          printf("%c",p[i][j]);
31      }
32      printf("\n");
33  }
34  
35     return 0;
36  } 

优质内容筛选与推荐>>
1、[转] Searching and sorting a column from a related table in a CGridView
2、英雄联盟设计师:游戏动画压缩如何保质量
3、【转】DAY7附录1
4、终止当前循环,退出循环,退出当前过程的指令的什么
5、Servlet工作原理


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn