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

    L1-039. 古风排版

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    陈越

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

    输入格式:

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

    输出格式:

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

    输入样例:
    4
    This is a test case
    
    输出样例:
    asa T
    st ih
    e tsi
     ce s


    import java.util.Scanner;
    
    public class Main {
        public static char[][] a = new char[1001][1001];
    
        public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            int n = cin.nextInt();
            cin.nextLine();
            String str = cin.nextLine();
            int len = str.length();
            cin.close();
            int lie = len / n;
            if (len % n != 0) {
                ++lie;
            }
            int t = 0;
            for (int j = lie - 1; j >= 0; --j) {
                for (int i = 0; i < n; ++i) {
                    if (t != len) {
                        a[i][j] = str.charAt(t++);
                    } else {
                        a[i][j] = ' ';// 就是这里比较坑,我开始写的a[i][j]=''发现错误,一想根本不会输出,这里要输出空格
                    }
                }
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < lie; ++j) {
                    System.out.print(a[i][j]);
                }
                System.out.println();
            }
        }
    }

    题目链接地址https://www.patest.cn/contests/gplt/L1-039

    ========================================Talk is cheap, show me the code=======================================

    CSDN博客地址:https://blog.csdn.net/qq_34115899
  • 相关阅读:
    列表推导式,生成器表达式
    迭代器,生成器初始
    装饰器的进阶
    函数名用途,初始装饰器
    函数参数,和空间
    py文件的操作
    字符串相关操作
    python基础二
    Django简介
    Django初识
  • 原文地址:https://www.cnblogs.com/lcy0515/p/9179804.html
Copyright © 2011-2022 走看看