首页 > 其他 > 详细

开始搬砖!

时间:2019-03-11 22:25:12      阅读:172      评论:0      收藏:0      [点我收藏+]

开始搬砖!

技术分享图片
 1 #include<stdio.h>
 2 #include<iostream>
 3 
 4 bool GetResult(int **& array, unsigned x, unsigned y)
 5 {
 6     array = new int *[x];
 7     for (unsigned i = 0; i < x; ++i)
 8     {
 9         array[i] = new int[y];
10     }
11 
12     int t = 0;
13     auto length = x > y ? x : y;
14     for (unsigned i = 0; i < 2 * length - 1; ++i)
15     {
16         for (int j = i; j >= 0; --j)
17         {
18             if (x > (i - j) && y > j)
19                 array[i - j][j] = ++t;
20         }
21     }
22     return true;
23 }
24 
25 void DeleteResult(int **&array, unsigned x, unsigned y)
26 {
27     for (unsigned i = 0; i < x; ++i)
28     {
29         delete array[i];
30     }
31     delete array;
32     array = nullptr;
33 }
34 
35 int main()
36 {
37     unsigned x, y;
38     std::cin >> x >> y;
39     int ** result = nullptr;
40     if (GetResult(result, x, y))
41     {
42         for (unsigned i = 0; i < x; ++i)
43         {
44             for (unsigned j = 0; j < y; ++j)
45             {
46                 printf("%d ", result[i][j]);
47             }
48             printf("\n");
49         }
50         DeleteResult(result, x, y);
51     }
52     return 0;
53 }
View Code

Hyapp

开始搬砖!

原文:https://www.cnblogs.com/hyapp/p/10513602.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!