题目链接:1036 跟奥巴马一起编程 (15 分)
这道题目很简单。
需要注意四舍五入(double类型+0.5 强制转化为int即可)
1 #include <bits/stdc++.h>
2 using namespace std;
3
4 int main()
5 {
6 int column,row;
7 cin>>
column;
8 char c;
9 cin>>
c;
10 double a=column/
2.0+
0.5;
11 row=(
int)a;
12 string str1,str2;
13 str1=str2=
"";
14 for(
int i=
0;i<column;i++
)
15 str1+=
c;
16 str2+=
c;
17 for(
int i=
0;i<column-
2;i++
)
18 str2+=
" ";
19 str2+=
c;
20 cout<<str1<<
endl;
21 for(
int i=
0;i<row-
2;i++
)
22 cout<<str2<<
endl;
23 cout<<str1<<
endl;
24 }
转载于:https://www.cnblogs.com/ManOK/p/10293349.html