解题思路:图形可以分成四个部分,i<n/2+1 i==n/2+1 i>n/2+1 和末尾x x
注意事项:
真tm坑 输出x 要求是大写的
参考代码:
#include <bits/stdc++.h>
using namespace std;
void DNA(int n){
for(int i=1,k=1,s=1;i<n;i++){
if(i==(n/2+1)){ //第一部分
for(int j=1;j<i;j++)
cout<<' ';
cout<<'X';
for(int j=1;j<i;j++)
cout<<' ';
cout<<endl;
}
else if(i<(n/2+1)){ // 第二部分
for(int j=1;j<i;j++)
cout<<' ';
cout<<'X';
for(int j=1;j<=n-i-k;j++)
cout<<' ';
cout<<'X';
cout<<endl;
k++;
}
else{
for(int j=1;j<=n-i;j++) //第三部分
cout<<' ';
cout<<'X';
for(int j=1;j<=s;j++)
cout<<' ';
cout<<'X';
cout<<endl;
s+=2;
}
}
}
int main(){
int time;
cin>>time;
while(time--){
int n,m;
cin>>n>>m;
int temp=m;
while(temp--)
DNA(n);
cout<<'X'; //第四部分x x
for(int i=1;i<=n-2;i++)
cout<<' ';
cout<<'X';
cout<<'\n'<<'\n';
}
}
0.0分
0 人评分
WU-拆分位数 (C++代码)浏览:789 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:902 |
核桃的数量 (C语言代码)浏览:672 |
1054题解浏览:467 |
C语言程序设计教程(第三版)课后习题9.6 (C语言代码)浏览:588 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:546 |
Hello, world! (C语言代码)浏览:826 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:450 |
printf基础练习 (C语言代码)浏览:1809 |
幸运数 (C++代码)浏览:2871 |