题解 | #Hello World for U#
Hello World for U
https://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b
#include <cstdio> #include <string> #include <map> #include <cmath> #include <vector> #include <climits> #include <iostream> #include <algorithm> #include <bitset> using namespace std; int main(){ string str1; int length; int max; while(cin>>str1){ string result=" "; length=str1.size(); for (int i = 0; i < length-2*i; ++i) { max=i; } //max代表n1 n3长度 不包括底部的那一个字符 for (int i = 0,j=length-1; i<max; ++i,--j) { result=result.substr(0,length-2*max-2); printf("%c%s%c\n",str1[i],result.c_str(),str1[j]); } //打印最后一行 printf("%s\n",str1.substr(max,length-2*max).c_str()); } }