题解 | #Hello World for U#
Hello World for U
https://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b
忽略多次输入,写于2024.3.18
#include <iostream> #include <algorithm> #include <cstring> using namespace std; int main() { int i, j; string str; cin >> str; int len = str.size(); int n1 = (len + 2) / 3; // 输的字符串的长度 int n3 = len - 2 * (n1 - 1); for (i = 0; i <= n1 - 2; i++) { cout << str[i]; for (j = 0; j < n3 - 2; j++) { cout << " "; } cout << str[len - 1 - i] << endl; } for (i = n1 - 1; i <= len - n1; i++) { cout << str[i]; } cout << endl; return 0; }