zoukankan      html  css  js  c++  java
  • 蓝桥杯历届试题 打印十字图

    主要是把图形分析清楚,把循环理清楚就好。这里我是用了二维数组把图存下来,全都初始化为点号,然后通过循环来更改某些部分为$,最后输出二维数组。

     1 #include<iostream>
     2 #include<cstring>
     3 
     4 using namespace std;
     5 
     6 char num[130][130];
     7 
     8 void tu(int n)
     9 {
    10     int cont=n;
    11     int j=1;
    12     int row=9+(n-1)*4;
    13     for(int i = 3; i <= row/2+1; i=i+2)
    14     {
    15         num[j][i]=num[j+1][i]=num[j+2][i]='$';
    16         num[j][row-i+1]=num[j+1][row-i+1]=num[j+2][row-i+1]='$';
    17         num[row-j+1][i]=num[row-j][i]=num[row-j-1][i]='$';
    18         num[row-j+1][row-i+1]=num[row-j][row-i+1]=num[row-j-1][row-i+1]='$';
    19         
    20         num[j+2][i-1]=num[j+2][i-2]='$';
    21         num[j+2][row-i+2]=num[j+2][row-i+3]='$';
    22         num[row-j-1][i-1]=num[row-j-1][i-2]='$';
    23         num[row-j-1][row-i+2]=num[row-j-1][row-i+3]='$';
    24         
    25         int temp=i+1;
    26         while(temp<=row/2+1)
    27         {
    28             num[j][temp]=num[j][row-temp+1]=num[row-j+1][temp]=num[row-j+1][row-temp+1]='$';
    29             temp++;
    30         }
    31         j+=2;
    32         temp=j;
    33         while(temp<=row/2+1)
    34         {
    35             num[temp][i-2]=num[temp][row-i+3]=num[row-temp+1][i-2]=num[row-temp+1][row-i+3]='$';
    36             temp++;
    37         }
    38     }
    39     for(int i = 1; i <= row;i++)
    40     {
    41         for(int j = 1; j <= row; j++)
    42             cout<<num[i][j];
    43         cout<<endl;
    44     }
    45     
    46 }
    47 int main()
    48 {
    49     int n;
    50     while(cin>>n)
    51     {
    52         memset(num,'.',sizeof(num));
    53         tu(n);
    54     }
    55     return 0;
    56 }
  • 相关阅读:
    xStream完美转换XML、JSON
    遍历Map的四种方法(转)
    MyEclipse下的svn使用(转)
    tomcat部署,tomcat三种部署项目的方法
    Linux常用命令大全
    MAP
    (转)数据库索引作用 优缺点
    MySql 总结
    python中easygui的安装方法
    python中easygui的安装方法
  • 原文地址:https://www.cnblogs.com/Xycdada/p/6444823.html
Copyright © 2011-2022 走看看