文章

64

粉丝

66

获赞

64

访问

4.8k

头像
字符棱形 (找规律)题解:

#include <bits/stdc++.h>
using namespace std;

int n; 

int main()
{
	cin >> n;
	int t = n, cnt = 1;
    //打印n行,上半
	while(t --)
	{
		for(int i = 1; i <= t; i ++)
			cout <<  " ";
		for(int i = 1; i <= cnt; i ++)
			cout << '*';
			
		cout << endl;
		cnt += 2;
	}
	//打印n-1行,下半
	cnt -= 2;
	t = n;
	while(t --)
	{
		cnt -= 2;
		for(int i = 1; i <= n - t; i ++)
			cout <<  " ";
		for(int i = 1; i <= cnt; i ++)
			cout << '*';
			
		cout << endl;
	}
	
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发