L1-039 古风排版 (20 分)

本文介绍了一种将现代文本转换为古代风格排版的方法。通过一个简单的C语言程序实现从左到右竖向排版的效果,适用于不超过1000字符的字符串。该程序能够根据指定的列宽进行换行。
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  } 

 

 

转载于:https://www.cnblogs.com/tingtin/p/10618322.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值