Hello World for U
这是一道数学问题:
n1=n3=max{ k | k<=n2 for n3=<n2<=N}且n1+n2+n3-2=N;时求n1,n3的值及n2的值,因为是三个边且要让三条边尽量相等,所以对n+2/3即可得到n1,n3
解答:
#include<iostream>
using namespace std;
int main() {
int n1, n2, n3, i, j, k;
string s;
cin >> s;
int len = s.size();
n1 = n3 = (len + 2) / 3;
n2 = len - n1 * 2 + 2;
for (i = 0; i < n1 - 1; i++) {
cout << s[i];
for (j = 0; j < n2 - 2; j++) cout << ' ';
cout << s[len - 1 - i] << endl;
}
for (j = 0; j < n2; j++, i++) cout << s[i];
return 0;
}