HDU 2565.放大的X

題目: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");
}
總結: 水題, 注意每行後面不要有多餘的空格.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章