PAT 1031 Hello World for U
AC代码
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int high=(s.size()+2)/3; // u形高度
int bottom=s.size()+2-2*high; // u形底部长度
for(int i=0;i<high-1;i++){
// 按行输出底部之外的部分 头+(bottom-2)个空格+尾
cout<<s[i];
for(int j=0;j<bottom-2;j++) cout<<' ';
cout<<s[s.size()-1-i]<<endl;
}
for(int i=high-1;i<s.size()-high+1;i++) cout<<s[i]; 输出
return 0;
}