题解 | Hello World for U
Hello World for U
https://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b
#include <iostream> #include <string> #include <cmath> using namespace std; int main(){ string str; while(cin >> str){ int len = str.size(); double k = (double)(len - 2) / (double)(3); int num; if(k - floor(k) >= 0.5){ num = ceil(k); }else{ num = floor(k); } //确定从第几个字母折叠 for(int i = 0; i < num; i ++){ cout << str[i]; for(int j = 0; j < len - 2 - 2 * num; j++){ cout << " "; } cout << str[len - i -1] << endl; } for(int i = 0; i < len - 2 * num; i++){ cout << str[num + i]; } cout << endl; } return 0; }