#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
int width,height;
char C;
cin >> width >> C;
if(width%2)
height=width/2+1; //宽度为偶数,行数为宽度/2+1
else
height=width/2;/ //宽度为奇数,行数为宽度/2
for(int i=0;i<height;i++)
{
if(i==0||i==height-1) //第一行或最后一行
{
string s(width,C); //输出个数为宽度的指定字符C
cout << s << endl;
}
else //中间行数时
{
cout << C; //先输出左边的字符C
string s(width-2,' '); //再输出width-2个的空格
cout << s;
cout << C << endl; //再输出右边的字符C
}
}
return 0;
}
PAT (Basic Level) Practice 1036 跟奥巴马一起编程 (15分)
最新推荐文章于 2020-08-24 18:38:20 发布