L1-1 古风排版(20 分)
输入格式:
输入在第一行给出一个正整数N(<100),是每一列的字符数。第二行给出一个长度不超过1000的非空字符串,以回车结束。
输出格式:
按古风格式排版给定的字符串,每列N个字符(除了最后一列可能不足N个)。
输入样例:
4
This is a test case
输出样例:
啊。按规律输出就好
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <vector>
#include <set>
using namespace std;
const int maxn = 5;
int main()
{
int n;
scanf("%d",&n);
string s;
getchar();
getline(cin,s);
int y=s.length()%n;//行数,不足补“ ”
int t=s.length()/n;//列数
if(y<n)t++;//有一行不满
for(int k=0;k<n;k++){
for(int j=0;j<t;j++){
if((n*(t-j-1)+k)>s.length()){cout<<" ";}//不满行的处理
else cout<<s[n*(t-j-1)+k];
}
cout<<endl;
}
return 0;
}