题解 | #Hello World for U#
Hello World for U
https://www.nowcoder.com/practice/c6e414fddd7c401887c350c9cc41f01b
注意区分str.size()是否是3的倍数
#include <iostream>
using namespace std;
int main(){
string str;
while (cin >> str){
int temp;
if (str.size()%3 == 0) //3的倍数 则计算完n1后要减1
temp = str.size()/3-1;//n1 n3
else temp = str.size()/3; //否则不用减
int p = str.size()-2*temp-2;//空格
int i,j;
//输出n1 N3
for (i = 0,j = str.size()-1; i<temp;i++,j--){
cout << str[i];
for (int k =1;k <= p;k++) cout<<" ";
cout << str[j]<<endl;
}
//输出n2
for (; i <=j;i++){//n2
cout <<str[i];
}
cout<<endl;
}
}

