古风排版(C语言实现)
生活随笔
收集整理的這篇文章主要介紹了
古风排版(C语言实现)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Description
中國的古人寫文字,是從右向左豎向排版的。本題就請你編寫程序,把一段文字按古風排版。
Input
輸入在第一行給出一個正整數N(<100),是每一列的字符數。
第二行給出一個長度不超過1000的非空字符串,以回車結束。
Output
按古風格式排版給定的字符串,每列N個字符(除了最后一列可能不足N個)。
Sample Input 1?
4 This is a test caseSample Output 1
asa T st ih e tsice s #include <stdio.h> #include<string.h> int main() {char a[1000],b[100][100]={' '};int n,t=0,total=0;//t為列數,total為字符數scanf("%d", &n);getchar();//吸收\ngets(a);int lenth = strlen(a);//總字符數while (total < lenth)//計算出列數{total += n;t++;}total = 0;//循環利用totalfor (int i = t-1; i>=0; i--)//從最后一列向下輸入b數組,按順序放入b數組里面{for (int k = 0; k < n; k++){if (total < lenth)//控制不超過總字符數b[k][i] = a[total++];}}for (int i = 0; i < n; i++){for (int k = 0; k < t; k++){if (b[i][k] != '\0')//如果不是空字符就輸出,是空字符就輸出空格{printf("%c", b[i][k]);}else putchar(' ');}putchar('\n');}return 0; }?
總結
以上是生活随笔為你收集整理的古风排版(C语言实现)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python搭建网盘网站_搭建nextc
- 下一篇: ITE Super IO入门篇