[C++]蓝桥杯 ADV-99. 栅格打印问题

问题描述
  编写一个程序,输入两个整数,作为栅格的高度和宽度,然后用“+”、“-”和“|”这三个字符来打印一个栅格。
  输入格式:输入只有一行,包括两个整数,分别为栅格的高度和宽度。
  输出格式:输出相应的栅格。
  输入输出样例
样例输入
3 2
样例输出

在这里插入图片描述

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

发布了87 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43356428/article/details/104934145