第二週test 2.空心三角形 HDU - 2091
阿新 • • 發佈:2018-12-14
#include <iostream> using namespace std; int main() { int x = 9999; char a; int n; char *A=NULL; A = new char[x]; int *N = NULL; N = new int[x]; int k; for (k=0;;++k) { cin >> A[k] ; if (A[k] == '@') break; cin >>N[k]; } for(int i=0;i<k;++i) { a = A[i]; n = N[i]; char**p = new char*[n]; for (int i = 0; i < n; ++i) { p[i] = new char[2 * n - 1]; for (int t = 0; t < 2 * n - 1; ++t) { p[i][t] = ' '; } } for (int i = 0; i < n; ++i) { if (i == 0) //第一行 { p[0][n - 1] = a; } else if (i == n - 1) //最後一行 { for (int j = 0; j < i + 1; ++j) { p[n - 1][j] = a; p[n - 1][2 * n - 1 - j] = a; } } else //中間 { p[i][n - 1 - i] = a; p[i][n - 1 + i] = a; } } for (int i = 0; i < n; ++i) //顯示輸出 { for (int t = 0; t < 2 * n - 1; ++t) { cout << p[i][t]; } if(i!=n-1)cout << endl; } if(i!=k-1)cout << endl<<endl; } }