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  } 

 

 

posted on 2019-03-28 22:42  cltt  阅读(260)  评论(0编辑  收藏  举报

导航