题目描述:
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int col,row;
char c;
cin >> col >> c;
if(col % 2 == 0){
row = col/2;
}else{
//注意要强制转换结果类型,否则表达式结果小数部分被截去,无法对小数点后四舍五入
row = round((double)col/2);
//也可直接row = col / 2 + 1
}
for (int i = 0; i < col; i++) {//首行
cout << c;
}
cout << endl;
for (int i = 0; i < row-2; i++) {//中间row-2行
cout << c;
for (int j = 0; j < col-2; j++) {
cout <<" ";
}
cout << c;
cout << endl;
}
for (int i = 0; i < col; i++) {//尾行
cout << c;
}
cout << endl;
return 0;
}