【题意】
1、两侧面数量要相等。
2、下面的数量不小于两侧面的数量
3、侧面的数,尽可能的大。
4、两侧面的数量与下面的数量的和满足题目给的等式关系。
【C++中字符处理】
关键点:遍历循环字符串中的所有字符
#include<iostream>
#include<string>
using namespace std;
char arr[80] = {};
void test()
{
string str;
int num = 0;
int sum = 0;
int n_1 = 0 , n_2 = 0;
cin >> str;
//for (int i = 0; i < str.length(); i++)
//{
// cout << str[i] << endl;
//}
num = str.length();
//cout << "num:" << num << endl;
//找出侧面与下面的数量关系:n1为侧面,n2为下面
for (int n1 = 0; n1 < num; n1++)
{
for (int n2 = n1; n2 < num; n2++)
{
sum = 2 * n1 + n2;
if (sum - 2 == num)
{
n_1 = n1;
n_2 = n2;
//cout << "n1:" << n1 << endl;
//cout << "n2:" << n2 << endl;
break;
}
}
}
//输出
//n1为行
int count = 0;
for (int j = 0; j < n_1; j++)
{
if (j != n_1 - 1) {
cout << str[j];
for (int k = 0; k < n_2 - 2; k++)
{
cout << " ";
}
cout << str[(num - j) -1];
cout << endl;
count++;
}
else
{
for (int k = 0; k < n_2; k++)
{
cout << str[count];
count++;
}
cout << endl;
}
}
}
int main()
{
test();
return 0;
}