老师我晕课10


私信TA

用户名:1710819010

访问量:10393

签 名:

最后一次

等  级
排  名 481
经  验 4556
参赛次数 7
文章发表 16
年  龄 0
在职情况 学生
学  校 贺州学院
专  业

  自我简介:

非常非常菜的菜鸡

解题思路:图形可以分成四个部分,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 人评分

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

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区