这题只需要一个一个判断每个字符的位置,然后再输出就行了;
注意:打印的行数和列数分别是n2+1和m2+1。
下面出示代码:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
for(int i=1;i<=n*2+1;i++){
for(int j=1;j<=m*2+1;j++){
if(i%2){
if(j%2)cout<<'+';
else cout<<'-';
}
else{
if(j%2)cout<<'|';
else cout<<' ';
}
}
cout<<endl;
}
return 0;
}

674

被折叠的 条评论
为什么被折叠?



