码迷,mamicode.com
首页 > 编程语言 > 详细

武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

时间:2014-12-12 14:37:44      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   io   ar   color   sp   for   on   

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("\n");
35             }            
36         }    
37     }    
38     return 0;  
39 }  

 

武汉科技大学ACM :1001: 华科版C语言程序设计教程(第二版)课后习题3.12

标签:des   style   blog   io   ar   color   sp   for   on   

原文地址:http://www.cnblogs.com/liuwt365/p/4159523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!