1036 跟奥巴马一起编程 (15 分)

题目:


思路:

没什么难点,注意四舍五入的取法即可。只有奇数或偶数,奇数取50%的小数部分必为0.5,所以必定进位。

代码:

 1 #include <iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int n, m;
 7     char c;
 8     cin >> n >> c;
 9     if(n % 2 == 0)
10         m = n / 2;
11     else
12         m = n / 2 + 1;
13     for(int i = 0; i < n; i++)
14     {
15         cout << c;
16     }
17     cout << endl;
18     for(int i = 1; i < m - 1; i++)
19     {
20         cout << c;
21         for(int j = 1; j < n-1; j++)
22         {
23             cout << " ";
24         }
25         cout << c << endl;
26     }
27     for(int i = 0; i < n; i++)
28     {
29         cout << c;
30     }
31     return 0;
32 }

 

posted @ 2019-07-04 14:46  Anzer  阅读(293)  评论(0编辑  收藏  举报