zoukankan      html  css  js  c++  java
  • L1-039 古风排版

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

    输入格式:

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

    输出格式:

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

    输入样例:

    4
    This is a test case
    

    输出样例:

    asa T
    st ih
    e tsi
     ce s
    
     
    思路:找规律题,考察对二维数组处理能力的掌握,注意补空格的情况......
     
     1 #include <iostream>
     2 #include<cstring>
     3 #include<cmath>
     4 using namespace std;
     5 int main()
     6 {
     7     int n;
     8     string str;
     9     scanf("%d",&n);
    10     getchar();
    11     getline(cin,str);
    12     int len=str.length();
    13     int h;
    14     h=len/n;
    15     if(h*n<len)
    16       h=h+1;
    17     char out_str[100][100];
    18     int count=0;
    19     for(int j=h-1;j>=0;j--)
    20     {
    21         for(int i=0;i<n;i++)
    22         {
    23             if(count>=len)
    24                     out_str[i][j]=' ';
    25             else 
    26                     out_str[i][j]=str[count];
    27             count++;
    28         }
    29     }
    30     for(int i=0;i<n;i++)
    31     {
    32         for(int j=0;j<h;j++)
    33         {
    34             cout<<out_str[i][j];
    35         }
    36         cout<<endl;
    37     }
    38     return 0;
    39 }
    大佬见笑,,
  • 相关阅读:
    sh_04_第1个函数改造
    sh_03_第1个函数
    sh_02_快速体验
    sh_01_九九乘法表
    11_测试模块
    sh_12_转义字符
    sh_11_九九乘法表
    sh_10_嵌套打印小星星
    Mariadb/Redis数据库
    部署django项目
  • 原文地址:https://www.cnblogs.com/xwl3109377858/p/10305679.html
Copyright © 2011-2022 走看看