wu


私信TA

用户名:cncfvc

访问量:215755

签 名:

读研狗没有时间刷题了~~

等  级
排  名 2
经  验 36084
参赛次数 8
文章发表 265
年  龄 25
在职情况 学生
学  校 电子科技大学
专  业 通信工程

  自我简介:

写代码 真好玩 ~

找完规律之后  注意如果宽度和高度输入0的话 那么肯定输出任何东西的

所以要排除0的特殊情况

参考代码:

#include<iostream>
using namespace std;
int main()
{
	//freopen("data.in.txt","r",stdin);
	//freopen("data.out.txt","w",stdout);
	int h,w;
	while(cin>>h>>w)
	{
		if(h==0||w==0)
		{
			return 0;
		}
		for(int i=1;i<=2*h+1;i++)
		{
		  for(int j=1;j<=2*w+1;j++)
		 {
			   if(i%2==1)
			 {
			   if(j%2==1)
			   {
			   	cout<<"+";	
			   } 
			   else
			   {
			   	cout<<"-";
			   }
			}
			else if(i%2==0)
			{
				if(j%2==1)
				cout<<"|"; 
				else
				cout<<" ";
				
			}
		  } 
			cout<<endl;
		}	
	}
	return 0;
 }


 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区