http://acm.hdu.edu.cn/showproblem.php?pid=2565
#include<iostream>
#include<string>
using namespace std;
int main(){
int t;
int a;
cin >> t;
while (t--){
cin >> a;
for (int n = 0; n < a / 2; n++){ //上部
for (int j = 0; j < n; j++)
cout << " ";
cout << "X";
for (int i = 0; i <a - 2*(n+1); i++)
cout << " ";
cout << "X";
cout << endl;
}
for (int n = 0; n < a / 2; n++){ //中部
cout << " ";
}
cout << "X" << endl;
for (int n = a / 2; n > 0; n--){//下部
for (int j = n - 1; j > 0; j--){//wen
cout << " ";
}
cout << "X";
for (int i = a - 2 * n; i > 0; i--)
cout << " ";
cout << "X" << endl;
}
cout << endl;
}
}
for循环可以“逆序”使用