ceil() 向上取整
floor() 向下取整
round()四舍五入取整
#include<iostream>
#include<math.h>
using namespace std;
void test()
{
double n;
cin >> n;
char x;
cin >> x;
double y;
y = n / 2;
y = round(y);
//cout << round(y) << endl;
for (int i = 0; i < y; i++)
{
if (i == 0) {
for (int j = 0; j < n; j++)
{
cout << x;
}
}
if (i > 0 && i < y - 1)
{
cout << x;
for (int k = 0; k < n - 2; k++) {
cout << " ";
}
cout << x;
}
if (i == y - 1)
{
for (int j = 0; j < n; j++)
{
cout << x;
}
}
cout << endl;
}
}
int main()
{
test();
return 0;
}