中国の古代人は右から左に縦に文字を書いた。この質問のために、古代のスタイルに従ってテキストの段落を植字するプログラムを書いてください。
入力フォーマット:
各列の文字数である正の整数N(<100)を最初の行に入力します。2行目は、長さが1000を超えない空でない文字列を示し、キャリッジリターンで終わります。
出力フォーマット:
指定された文字列を古代のスタイルでタイプセットし、各列にN文字を使用します(最後の列がN未満の場合を除く)。
入力サンプル:
4
This is a test case
サンプル出力:
asa T
st ih
e tsi
ce s
ACコード:
// main.cpp
// 猫猫头
//
// Created by Mintink on 2020/1/12.
// Copyright © 2020 Mintink. All rights reserved.
//
#include<iostream>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<vector>
#include<queue>
#include<array>
#include <stdlib.h>
#include <stdio.h>
#include<cstdio>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
//tuple<int,string,int>p[55];
//pair<int,string>male[55],female[55];
priority_queue<ll,vector<ll>,greater<ll> >qa;//升序,大根堆
priority_queue<ll>qd;//降序,小根堆
//const int mod=10e9+7;
typedef long long ll;
//vector<int>v;
char map[110][110];
int main()
{
int N;
cin>>N;
//input \n
string str;
getline(cin,str);
//input sentence
string sentence;
getline(cin,sentence);
int len=sentence.size();
int width;
if(len%N==0)
width=len/N;
else
width=len/N+1;
int mark=0;
for(int j=width-1;j>=0;j--)
{
for(int i=0;i<N;i++)
{
if(mark<=(len-1))
map[i][j]=sentence[mark++];
else
map[i][j]='$';
}
}
for(int i=0;i<N;i++)
{
for(int j=0;j<width;j++)
{
if(map[i][j]=='$')
cout<<" ";
else
cout<<map[i][j];
}
cout<<endl;
}
return 0;
}