赞
踩
打印类的题,一般都是找规律,通过for控制打印......
AC代码如下:
- #include<iostream>
- using namespace std;
- //@@@@@@@ @ @ @@@@@
- // @ @ @ @ @
- // @ @ @ @ @
- // @ @@@@@@@ @ @
- // @ @ @ @ @
- // @ @ @ @ @
- //@@@@@@@ @ @ @@@@@
- int main()
- {
- int n;
- cin >> n;
- int j;
- for (int i = 1; i <= n; i++)
- {
- if (i == 1||i==n)
- {
- for (j = 1; j <= n; j++)
- cout << '@';
- cout << " ";
- cout << '@';
- for (j = 2; j <= n - 1;j++)
- cout << ' ';
- cout << '@';
- cout << " ";
- for (j = 1; j <= n - 2; j++)
- cout << '@';
- cout << endl;
- }
- else
- {
- for (j = 1; j <= n - i; j++)
- cout << ' ';
- cout << '@';
- for (j = 1; j <= i - 1; j++)
- cout << ' ';
- cout << " ";
- if (i != n / 2 + 1)
- {
- cout << '@';
- for (j = 2; j <= n - 1; j++)
- cout << ' ';
- cout << '@';
- }
- else
- {
- for (j = 1; j <= n; j++)
- cout << '@';
- }
- cout << " ";
- cout << '@';
- if (i == 2 || i == n - 1)
- {
- for (j = 1; j <= n - 3; j++)
- cout << ' ';
- cout << '@';
- }
- else
- {
- for (j = 1; j <= n - 2; j++)
- cout << ' ';
- cout << '@';
- }
- cout << endl;
- }
- }
- return 0;
- }
早上补题中
感谢大家的阅读!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。