zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

    Problem Description

    输入n,输出对应的边长为n的空心正六边形。

    为方便看图,样例中点 '.' 表示空格,打印图形时请打印空格而非小圆点。

    Input

     边长n.(n<=20)

    Output

     边长为n的正六边形

    Sample Input

    5
    

    Sample Output

    .....*****
    ....*.....*
    ...*.......*
    ..*.........*
    .*...........*
    ..*.........*
    ...*.......*
    ....*.....*
    .....*****
     1 #include<stdio.h>
     2 #include<math.h>
     3 void prt(char c, int count)  
     4 {  
     5     while(count--)  
     6     {  
     7         printf("%c",c);  
     8     }  
     9 }  
    10 
    11 int main()  
    12 {  
    13     int N, L;
    14     while(scanf("%d",&N)!=EOF)
    15     {
    16         if(N>0 && N<=20)
    17         {
    18             L=0;
    19             for(; L < 2 * N - 1; L++)  
    20             {  
    21                 prt(' ', 1); 
    22                 prt(' ', abs(N - L-1)); 
    23                 
    24                 if(0 == L || L == 2 * N - 2)  
    25                 {  
    26                     prt('*', N);  
    27                 }  
    28                 else  
    29                 {  
    30                     prt('*', 1);
    31                     prt(' ', 3 * N - 4 -(abs(L+1 - N) * 2));
    32                     prt('*', 1);
    33                 }  
    34                 printf("
    ");
    35             }            
    36         }    
    37     }    
    38     return 0;  
    39 }  
  • 相关阅读:
    java基础篇6之代理
    JavaWeb 过滤器应用之页面静态化
    JavaWeb 之过滤器
    JavaWeb 之监听器
    分页
    Linux 入门
    多条件组合查询
    Service 事务(JdbcUtils 升级)
    BaseServlet 介绍
    dbUtils 工具类介绍
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4159523.html
Copyright © 2011-2022 走看看