PAT 乙级 1036 跟奥巴马一起编程 v1.0
1. 题目简述及在线测试位置
1.1 按要求打印字符,为了让结果看上去更像正方形,输出的行数实际上是列数的 50%(四舍五入取整)
1.2 在线测试位置:PAT 1036 跟奥巴马一起编程
2. 基本思路
打印的列数是现成的,行数是列数的50%(需要四舍五入)。第一行和最后一行需要打印列上的所有字符,其余行只需打印首个字符和最后字符。据此实现即可
3. 完整AC代码
#include <iostream>
using namespace std;
int main()
{
int Column, Row;
char Symbol;
cin >> Column >> Symbol;
Row = Column * 0.5;//输出的行数是列数的50% 四舍五入
if ( (float(Column)*0.5 - Row) >= 0.5)
Row++;
for (int i = 0; i < Column; i++)
cout << Symbol;
cout << endl;
for (int i = 2; i <= Row - 1; i++)
{
cout << Symbol;
for (int j = 0; j < Column - 2; j++)
cout << " ";
cout << Symbol;
cout << endl;
}
for (int i = 0; i < Column; i++)
cout << Symbol;
return 0;
}