n2随长度增加呈现出一个有规律的数列,从最短长度5开始,n2为:3,4,3,4,5,4,5,6,5,6,7,6,7,8,7,8,9,8,9,10......

#include<iostream>
#include<cstring> 
using namespace std;
int suren2(int len){//计算n2
	if(len%3==0||len%3==2) return len/3+2;
	else return len/3+1;
}
int main(){
	string a;
	int n1,n2;
	while(cin>>a){
		n2=suren2(a.length());
		n1=(a.length()-n2)/2;
		char c[n1+1][n2];    //输出的二维数组
		for(int i=0;i<n1+1;i++) for(int j=0;j<n2;j++) c[i][j]=' ';    //笨办法填空格
		for(int i=0;i<n1;i++) c[i][0]=a[i];    //填左边
		for(int i=0;i<n2;i++) c[n1][i]=a[n1+i];    //填下边
		for(int i=0;i<n1;i++) c[i][n2-1]=a[a.length()-i-1];    //填右边	
		for(int i=0;i<n1+1;i++){    //输出
			for(int j=0;j<n2;j++)    cout<<c[i][j];
			cout<<endl;
		}
	}
	return 0;
}