3228:【例38.2】 图形输出(C、C++、python)

3228:【例38.2】 图形输出

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

[例 38.2] 图形输出

信息学奥赛一本通-编程启蒙(C++版)在线评测系统

第37集 | 图形输出(3228)

https://www.douyin.com/video/7322060202130279720




C语言代码:

/*
3228:【例38.2】 图形输出
http://bas.ssoier.cn:8086/problem_show.php?pid=3228

用*输出菱形;
https://blog.csdn.net/m0_73551276/article/details/127385878
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
	char A;
	int a;
	scanf("%c%d",&A,&a);
 
	if(A=='Z')
	{
  		for(int i=0;i<a;i++)
		{
   			for(int j=0;j<a;j++)
			{
    			printf("*");
   			}
   			printf("\n");
  		}
 	}
 	else if(A=='L'){
  		for(int i=-a+1;i<a;i++)
		{
   			for(int j=0;j<abs(i);j++) printf(" ");
   			
			for(int j=0;j<2*a-2*abs(i)-1;j++) printf("*");
   			
			printf("\n");
  		}
  
 	}
 	
	return 0;
}



C++程序:

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans,num=1;
	bool sum=true;
	char ch;
	cin>>ch>>ans;
	
	if( ch=='Z' )
	{
		for(int i=1;i<=ans;i++)
		{
			for(int j=1;j<=ans;j++)
			{
				cout<<"*";
			}
			
			cout<<endl;
		}
	}
	else
	{
		for(int i=1;i<=ans*2-1;i++)
		{
			for(int k=1;k<=((ans*2-1)-num)/2;k++)
			{
				cout<<" ";
			}
		
			for(int j=1;j<=num;j++)
			{
				cout<<"*";
			}
			
			cout<<endl;
		
			if( i==ans )
			{
				sum=false;
			}
			
			if( sum==true )
			{
				num+=2;
			}
			else
			{
				num-=2;
			}
		}
	}
	
    return 0;
}


/*
3228:【例38.2】 图形输出
http://bas.ssoier.cn:8086/problem_show.php?pid=3228

用*输出菱形;
https://blog.csdn.net/m0_73551276/article/details/127385878
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
 char A;
 int a;
 cin >> A >> a;
 if(A=='Z'){
  for(int i=0;i<a;i++){
   for(int j=0;j<a;j++){
    printf("*");
   }
   printf("\n");
  }
 }
 else if(A=='L'){
  for(int i=-a+1;i<a;i++){
   for(int j=0;j<abs(i);j++) printf(" ");
   for(int j=0;j<2*a-2*abs(i)-1;j++) printf("*");
   printf("\n");
  }
  
 }
 return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	int n;
	cin>>a>>n;
	if(a=='Z'){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				cout<<"*";
			}
			cout<<endl;
		}
	}else{
		for(int i=1;i<n;i++){
			for(int j=1;j<=n-i;j++) cout<<" ";
			for(int j=1;j<2*i;j++) cout<<"*";
			cout<<endl;
		}
		for(int i=n;i>=1;i--){
			for(int j=1;j<=n-i;j++) cout<<" ";
			for(int j=1;j<2*i;j++) cout<<"*";
			cout<<endl;
		}
	}
	return 0;
}


python3程序:

a=input()

n=int( input() )

if a.strip()=="L":
            for i in range(1,n):
                        print(' '*(n-i)+'*'*(2*i-1) )

            for i in range(n,0,-1):
                        print(' '*(n-i)+'*'*(2*i-1) )
else:
            print(('*'*n+'\n')*n)



 




【洛谷】P3717 [AHOI2017初中组]cover 【python】

【洛谷】P3717 [AHOI2017初中组]cover 【python】_洛谷b2017python-CSDN博客

洛谷 P3817 小A的糖果 python解析

洛谷 P3817 小A的糖果 python解析_小a的糖果python-CSDN博客

洛谷 python P4017 最大食物链计数

洛谷 python P4017 最大食物链计数-CSDN博客

洛谷(Python) P4956 [COCI2017-2018#6] Davor

洛谷(Python) P4956 [COCI2017-2018#6] Davor_p4956 [coci2017-2018#6] davor pyth-CSDN博客

洛谷_P5741【深基7.例10】旗鼓相当的对手 - 加强版_python写法

洛谷_P5741【深基7.例10】旗鼓相当的对手 - 加强版_python写法_python旗鼓相当的对手-CSDN博客

洛谷 题单 官方精选 排序 Python实现

洛谷 题单 官方精选 排序 Python实现_p5143 攀爬者 python-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dllglvzhenfeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值