欢迎使用CSDN-markdown编辑器

来源:互联网 发布:prisma tensorflow 编辑:程序博客网 时间:2024/06/03 06:42

**

蓝桥杯 历届试题-打印十字图

**
一入眼就是根本看不出规则的乱七八糟的 $ 和 . ,研究了半个小时,实在是给跪了,上网查了下思路。。。nima, 真是醉了。
我的基本思想就是 二维数组存储0,1,然后判断输出。
首先你要用 excel表格把输出样例打进去,然后快速分析,调整一下列宽行高什么的就会看到这个

这里写图片描述

然后就大概有了一个直观的了解,我就是上网看到这幅图后瞬间就跪了。然后我们继续分析,感觉很对称,抠出来四分之一外加最中间那一行,就是这样

这里写图片描述

还是很对称吧,再抠

这里写图片描述

ok,好了,然后我们的思路就是 对角线复制,左右复制,上下复制,自己脑补动画

代码如下

#include <iostream>/* run this program using the console pauser or add your own getch, system("pause") or input loop */using namespace std;int array[130][130]={0};void show(int n){//负责打印数组    for (int i = 0; i < 4*n+5; ++i)    {        for (int j = 0; j < 4*n+5; ++j)        {            if (array[i][j]==1)            {                cout<<"$";            }            else                cout<<".";        }        cout<<endl;    }}void Eighth(int n){//把最小的那部分数组给初始化    for (int i = 2*n+2; i >1; i-=2)    {        array[i][i] = 1;        array[i][i-1] = 1;        array[i][i-2] = 1;    }    for (int i = 2*(n-1); i > -1; i-=2)    {        for (int j = i+2; j < 2*n+3; j++)        {            array[j][i] = 1 ;        }    }}void Copy_Dia_Qua(int n){//把八分之一复制成四分之一    for (int i = 1; i < 2*n+3; ++i)    {        for (int j = 0; j < i+1; ++j)        {            array[j][i] = array[i][j];        }    }}void  Copy_L_R(int n){//左右复制    for (int i = 0; i < 2*n+3; ++i)    {        for (int j = 0; j < 2*n+3; ++j)        {            array[i][4*n+4-j] = array[i][j];        }    }}void Copy_U_D(int n){//然后上下复制    for (int i = 0; i < 2*n+3; ++i)    {        for (int j = 0; j < 4*n+5; ++j)        {            array[4*n+4-i][j] = array[i][j];        }    }}int main(int argc, char** argv) {    int n;    cin>>n;    Eighth(n);    Copy_Dia_Qua(n);    Copy_L_R(n);    Copy_U_D(n);    show(n);    return 0;}
0 0
原创粉丝点击