1. 程式人生 > >PAT乙級-1036.跟奧巴馬一起編程(15)

PAT乙級-1036.跟奧巴馬一起編程(15)

alt space span pat content pac ima com 分享

題解技術分享

題解:

註意“行數是列數的50%(四舍五入)”

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

PAT乙級-1036.跟奧巴馬一起編程(15)