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

1156: 零起点学算法63——弓型矩阵

时间:2017-04-09 14:52:19      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:problems   led   copy   memory   print   mat   format   大于   code   

1156: 零起点学算法63——弓型矩阵

Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lld
Submitted: 3403  Accepted: 1284
[Submit][Status][Web Board]

Description

输出n*m的弓型矩阵

 

Input

多组测试数据
每组输入2个整数 n和m(不大于20)

 

Output

输出n*m的弓型矩阵,要求左上角元素是1,(每个元素占2个位置,靠右)

 

Sample Input 技术分享

 
4 3

 

Sample Output

 1  2  3
 6  5  4
 7  8  9
12 11 10

 

Source

 
 1 #include<stdio.h>
 2 #include<string.h>
 3 int main(){
 4     int n,m,a[20][20];
 5     while(scanf("%d%d",&n,&m)!=EOF){
 6         
 7         memset(a,0,sizeof(a));
 8         int tot,i,j;
 9         tot=a[i=0][j=0]=1;
10         while(tot<n*m){
11             while(j+1<m)
12               a[i][++j]=++tot;  
13               a[++i][j]=++tot;
14             while(j-1>=0)
15               a[i][--j]=++tot;
16               a[++i][j]=++tot;
17         }
18         
19         for(int i=0;i<n;i++){
20             for(int j=0;j<m-1;j++){
21                 printf("%2d ",a[i][j]);
22             }
23             printf("%2d\n",a[i][m-1]);
24         }
25     }
26     
27     return 0;
28 } 

//思想很重要!!!

1156: 零起点学算法63——弓型矩阵

标签:problems   led   copy   memory   print   mat   format   大于   code   

原文地址:http://www.cnblogs.com/dddddd/p/6684541.html

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