分析:给个字符串,无空格,模拟输出即可,按公式推导n1,n2,关键是while的代码
#include <iostream>
#include<cstring>
#include<vector>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<stack>
#include<algorithm>
#include<map>
#include<set>
#define MAX 99999999
using namespace std;
typedef long long ll;
char ans[1001][1001];
int main()
{
string s;
cin>>s;
int n1,n2,len;
len = s.size();
int temp = 1;
while((len + 2*temp) % 3 != 0){
temp ++;
}
n2 = (len + 2*temp) / 3;
n1 = n2 - temp + 1;
for(int i = 0;i<1001;i++)
for(int j = 0;j<1001;j++)
ans[i][j] = ' ';
int cnt = 0;
for(int i = 0;i<n1;i++)
ans[i][0] = s[cnt++];
for(int j = 1;j<n2;j++)
ans[n1-1][j] = s[cnt++];
for(int i = n1-2;i>=0;i--)
ans[i][n2-1] = s[cnt++];
for(int i = 0;i<n1;i++)
{
for(int j = 0;j<n2;j++)
cout<<ans[i][j];
cout<<endl;
}
return 0;
}