zoukankan      html  css  js  c++  java
  • 天梯赛题解 -L1-039 古风排版

    L1-039 古风排版 (20 分)
    中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。
    
    输入格式:
    输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
    
    输出格式:
    按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。
    
    输入样例:
    4
    This is a test case
    输出样例:
    asa T
    st ih
    e tsi
     ce s
    #include <iostream>
    #include <map>
    #include <set>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <cstdio>
    #include <cmath>
    using namespace std;
        int N;
        string s;
        string p[101];
    int main(){
        cin >> N;
        getchar();
        getline(cin,s);
        int len = s.length();
        int tr;
        tr = len/N;
        if(len%N!=0){
            ++tr;
        }
        for(int i=0;i<tr*N-len;i++){
            s += ' ';
        }
        for(int i=0;i<s.length();){
            for(int j=0;j<N&&i<s.length();j++,++i){
                p[j].insert(p[j].begin(),s[i]);
            }
        }
        for(int i=0;i<N;i++){
            cout << p[i] << endl;
        }
        return 0;
    }
  • 相关阅读:
    BZOJ 4245: [ONTAK2015]OR-XOR
    BZOJ 2535: [Noi2010]Plane 航空管制2
    COGS 2551. 新型武器
    cogs2550. 冰桥,升起来了!
    大数模板
    uva 1513(线段树)
    uva 11525(线段树)
    poj 3368(RMQ模板)
    hdu 4686 Arc of Dream(矩阵快速幂)
    poj 3321 Apple Tree(树状数组)
  • 原文地址:https://www.cnblogs.com/--zz/p/10617558.html
Copyright © 2011-2022 走看看