///////////////////////////////////3229:【例38.3】 X战警 string void cout(int n){ int k=0; int i=0; while(i<n) { if(i<=n/2) { k=k+1; } else k=k-1; int j=1; string str=""; while(j<=n){ if(j==k || j==n-k+1) str=str+"X"; else str=str+" "; j=j+1; } cout<<str<<endl; i=i+1; } } cout(11); cout(11); cout(11);
//////////////////////////////////////// 3229:【例38.3】 X战警 int n=21; int k=0; int i=0; while(i<n) { if(i<=n/2) { k=k+1; } else k=k-1; int j=1; while(j<=n){ if(j==k || j==n-k+1) cout<<"X"; else cout<<" "; j=j+1; } cout<<endl; i=i+1; }