题目:http://acm.hdu.edu.cn/showproblem.php?pid=2565
AC代码(C++):
#include <iostream> #include <queue> #include <string> #include <algorithm> #include <math.h> #define INF 0x3f3f3f3f #define eps 1e-8 using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < n; j++) { if (i == j&&i + j == n - 1) { cout << 'X'; cnt += 2; } else if (i == j || i + j == n - 1) { cout << 'X'; cnt++; } else cout << ' '; if (cnt == 2)break; } cout << endl; } cout << endl; } //system("pause"); }总结: 水题, 注意每行后面不要有多余的空格.