//00 01 02 03 04
//10 11 12 13 14
//20 21 22 23 24
//31 32 33 34 34
#include <string>
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(){
int n;
cin>>n;
string str;
getchar();
getline(cin,str);
int len=str.length();
int m;
//bool flag=true;//是4的倍数吗?
if(len%n!=0){//19/4=4-----4+1=5----5行
//flag=false;
m=len/n+1;//有几列?因为有4行,所以每1列都要有4个字符,如果只有19个字符,如题目,就要在最后补上空格,
}else{
m=len/n;//能被整除,空格都被字符填满
}
char c[1010][1010];
int k=0;
for(int i=m-1;i>=0;i--){//43210
for(int j=0;j<n;j++){//0123
if(k<len)//01
c[j][i]=str[k++];//04 14 24 34 //14 13 12 11 10
else//我给你的格子就是应该填满的,如果出现格子空着但是字符已经用完了,你就要用空格补上
c[j][i]=' ';
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)
cout<<c[i][j];
cout<<endl;
}
return 0;
}
/*
stack<int> s;
int l=str.length();
for(int i=0;i<len;i++)
s.push(str[i]);
char after[1010][1010];
for(int i=0;i<l/n;i++){//30 20 10 00 //31 21 11 01
for(int j=3;j>=0;j--){
if(!s.empty()){
after[j][i]=s.top();
s.pop();
}
}
}
int cmt=0;
for(int i=0;i<4;i++){//00 01 02 03
for(int j=0;j<n/l;j++){
cout<<after[i][j];
}
cout<<endl;
}
*/
|分类行列题目ji|7-7古风排版(20)
最新推荐文章于 2021-03-14 23:47:48 发布