题解 | #Hello World for U#
Hello World for U
https://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b
#include <iostream> #include <string> #include <cstring> using namespace std; const int N = 30; char res[N][N]; void printU(string s) { memset(res, 0, sizeof res); int n = s.size(); int n1 = (n + 2) / 3, n2 = n + 2 - 2 * n1; // cout << n1 << n2 <<endl; int i = 0, j; for(j = 1; j <= n1; j ++) res[j][1] = s[i ++]; for(j = 2; j <= n2; j ++) res[n1][j] = s[i ++]; for(j = n1 - 1; j; j --) res[j][n2] = s[i ++]; for(int i = 1; i <= n1; i ++) { for(int j = 1; j <= n2; j ++) { if(res[i][j] != 0) cout << res[i][j]; else cout << ' '; } cout << endl; } } int main() { string s; while (cin >> s) { // 注意 while 处理多个 case printU(s); } } // 64 位输出请用 printf("%lld")