藍橋杯訓練 蛇形矩陣 模擬
阿新 • • 發佈:2019-03-12
cout htm spa ble ref spl 藍橋杯 http urn
題目鏈接http://www.dotcpp.com/oj/problem1097.html
ac代碼:
#include<iostream> using namespace std; int n; int a[110][110]; int main() { while (cin >> n){ int sum = 0; int tot = n; int t = 1; while (tot--){ for (intView Codei = sum; i >=0; i--) a[i][sum - i] = t++; sum++; } //輸出 for (int i = 0; i < n; i++){ for (int j = 0; j < n - i; j++){ if (j == n - i - 1) cout << a[i][j]; elsecout << a[i][j] << ‘ ‘; } cout << endl; } } return 0; }
藍橋杯訓練 蛇形矩陣 模擬