zoukankan      html  css  js  c++  java
  • 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
    ",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
    ",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("
    ");
    33  }
    34  
    35     return 0;
    36  } 
     
  • 相关阅读:
    Java判断字符串是否包含数字
    char 与 String 之间的转换
    hive与hbase整合方式和优劣
    曾经的你-许巍
    Hbase表重命名 表改名
    Eclipse 快键键(持续更新)
    Linux 查看一个端口的连接数
    hbase性能调优(转载)
    Hbase优化记录
    记录下Linux难记实用的命令
  • 原文地址:https://www.cnblogs.com/tingtin/p/10618322.html
Copyright © 2011-2022 走看看