题解 | #Hello World for U#
Hello World for U
http://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b
#include <cstdio>
#include <string>
using namespace std;
int main() {
string str;
while (cin >> str) {
int len = str.size();
int n1 = len / 2;
int n2 = len - 2 * n1;
while (n1 + 1 > n2) {
n1--;
n2 = len - 2 * n1;
}
int i = 0;
while (i < n1) {
cout << str[i];
for(int j = 0; j < n2 - 2; j++) {
cout << ' ';
}
cout << str[len-i-1] << endl;
i++;
}
cout << str.substr(n1, n2) << endl;
}
return 0;
}