中国的古人写文字,是从右向左竖向排版的。本题就请你编写程序,把一段文字按古风排版。
输入格式:
输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
输出格式:
按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。
输入样例:
4
This is a test case
输出样例:
asa T
st ih
e tsi
ce s
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<double, int> PII;
const int N = 400010;
int Mod = 998244353;
int a[N], b[N];
void solve()
{
int n;
cin >> n;
cin.ignore();
string res;
getline(cin, res);
if(res.size() % n)
{
int t = res.size() % n;
for(int i = 1; i <= n - t; i ++)
res += ' ';
}
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= res.size() / n; j ++)
{
cout << res[res.size() - 1 - j * n + i];
}
if(i < n) cout << endl;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tt = 1;
// cin >> tt;
while (tt--)
{
solve();
}
return 0;
}

568

被折叠的 条评论
为什么被折叠?



