社区
数据结构与算法
帖子详情
都来帮我看看!~!!!请那位大哥帮帮忙?小弟先谢/..你们都来帮我看看
zezeze
2005-10-14 04:36:21
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
如图有如此规律的一个阵..题目意思..由用户输入要产生的行和列的值..然后根据这个规律给用户显示出用户输入的几行几列的阵!!
...全文
134
2
打赏
收藏
都来帮我看看!~!!!请那位大哥帮帮忙?小弟先谢/..你们都来帮我看看
1 2 6 7 15 3 5 8 14 16 4 9 13 17 22 10 12 18 21 23 11 19 20 24 25 如图有如此规律的一个阵..题目意思..由用户输入要产生的行和列的值..然后根据这个规律给用户显示出用户输入的几行几列的阵!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
djfu
2005-10-15
打赏
举报
回复
OK , 搞定!
【思路】:以斜向的对角线的值递增分析为主。
【源码】:如下:
#include <iostream>
using namespace std;
typedef int BOOL;
#define TRUE 1
#define FALSE 0
#define DownToUp TRUE
#define UpToDown FALSE
int min(int x, int y)
{
return x < y ? x : y;
}
int max(int x, int y)
{
return x > y ? x : y;
}
int main()
{
int nRow, nCol, nFoldLine;
cout << "Please enter matrix row and column number:" ;
cin >> nRow >> nCol;
cout << endl;
nFoldLine = nRow + nCol -1;
int i, j, nR, nC;
int **a = new int*[nRow];
for (i = 0; i < nRow; i++)
a[i] = new int[nCol];
for(i = 0; i < nRow; i ++)
for(j = 0; j < nCol; j ++)
a[i][j] = 0;
BOOL Order = DownToUp;
int nCurValue = 1;
for( i = 0; i < nFoldLine; i++ )
{
if(Order == UpToDown)
{
for(nR = max(0, i - nCol + 1); nR <= min(i, nRow-1); nR ++)
{
nC = i - nR;
a[nR][nC] = nCurValue ++;
}
}
else if(Order == DownToUp)
{
for(nR = min(nRow - 1, i); nR >= 0; nR --)
{
nC = i - nR;
if(nC >= nCol )
break;
a[nR][nC] = nCurValue ++;
}
}
Order = !Order;
}
cout << "The matrix's row = " << nRow << ",column = " << nCol << ", totoal size = " << nRow * nCol << endl;
cout << "The whole matrix is :" << endl;
for(i = 0; i < nRow; i ++)
{
for(j = 0; j < nCol; j++)
cout << a[i][j] << "\t" ;
cout << endl;
}
for (i = 0; i < nRow; i++)
delete [nCol] a[i];
delete [nRow] a;
getchar();
return 0;
}
【示例一】:
Please enter matrix row and column number:15 7
The matrix's row = 15,column = 7, totoal size = 105
The whole matrix is :
1 2 6 7 15 16 28
3 5 8 14 17 27 29
4 9 13 18 26 30 42
10 12 19 25 31 41 43
11 20 24 32 40 44 56
21 23 33 39 45 55 57
22 34 38 46 54 58 70
35 37 47 53 59 69 71
36 48 52 60 68 72 84
49 51 61 67 73 83 85
50 62 66 74 82 86 95
63 65 75 81 87 94 96
64 76 80 88 93 97 102
77 79 89 92 98 101 103
78 90 91 99 100 104 105
Press any key to continue
【示例二】:
Please enter matrix row and column number:5 5
The matrix's row = 5,column = 5, totoal size = 25
The whole matrix is :
1 2 6 7 15
3 5 8 14 16
4 9 13 17 22
10 12 18 21 23
11 19 20 24 25
Press any key to continue
【示例三】:
Please enter matrix row and column number:1 9
The matrix's row = 1,column = 9, totoal size = 9
The whole matrix is :
1 2 3 4 5 6 7 8 9
Press any key to continue
【示例四】:
Please enter matrix row and column number:9 1
The matrix's row = 9,column = 1, totoal size = 9
The whole matrix is :
1
2
3
4
5
6
7
8
9
Press any key to continue
xiaocai0001
2005-10-14
打赏
举报
回复
又是一个蛇形阵啊~~
http://community.csdn.net/Expert/topic/4300/4300725.xml?temp=.614773
看看上面那个帖子
跟你的阵基本上一个样
哪个学校计算机学硕好考吗,考计算机研究生,又想往网络方向发展,
请
各位
大哥
大姐推荐几所学校!谢谢!...
考计算机研究生,又想往网络方向发展,
请
各位
大哥
大姐推荐几所学校!谢谢!以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!考计算机研究生,又想往网络方向发展,
请
各位
大哥
大姐推荐几所学校!谢谢!我也想考研,你
看看
南宁大学怎么样?研究生想读计算机图像学方向,恳求推荐几所学校华中科技大学有个图像所,你可以
看看
他们的网页。华科的科研...
[项目实施失败讨论Case] “凭心而论,在这家公司很敬业的工作了3年多,老板最后给我下的评语,大家都
看看
吧,千万别和我走同一条路!”(摘自csdn)...
[Case] “凭心而论,在这家公司很敬业的工作了3年多,老板最后给我下的评语,大家都
看看
吧,千万别和我走同一条路!”(摘自csdn) 原文:http://community.csdn.net/Expert/topic/4420/4420345.xml?temp=.922909感觉非常有意义:1,这是一个典型的事情2,各种人的心态,想法,都在这里3,工作中遇到了这样的事情,需要怎么处理?4,工作...
java开发速成班培训课程(1)
[url=http://www.buildapp.net/java/show.asp?id=12400]jsp不能显示中文?
请
帮
忙解决一下 (悬赏:3分)[/url] [url=http://www.buildapp.net/java/show.asp?id=12399]
请
老师们
帮
我看下这段很短的代码,为什么结果会是这样? [/url] [url=http://www.build...
[Case] “凭心而论,在这家公司很敬业的工作了3年多,老板最后给我下的评语,大家都
看看
吧,千万别和我走同一条路!”(摘自csdn)...
原文:http://community.csdn.net/Expert/topic/4420/4420345.xml?temp=.922909感觉非常有意义:1,这是一个典型的事情2,各种人的心态,想法,都在这里3,工作中遇到了这样的事情,需要怎么处理?4,工作中遇到了楼主的老板,楼主,还有各位回帖人这样的人物,该怎么处理对待?下面是我摘下来的原文和回帖:凭心而论,在这家公司很敬业的工作了3年多,...
浏览器访问svn服务器文件,在浏览器上可以访问SVN服务器,但用TSVN访问不了,是什么原因?...
引用楼主linyoujushi的回复:各位前辈,
帮
帮
忙
。最近我在Debian上架设了SVN+APACHE2服务器,代码如下:DocumentRoot/datarepos/svn-reposServerNamesvn.jan.techRedirectMatch^(/repos)$$1/ErrorLog/var/log/apache2/subversion/error.logLogLev...
数据结构与算法
33,028
社区成员
35,337
社区内容
发帖
与我相关
我的任务
数据结构与算法
数据结构与算法相关内容讨论专区
复制链接
扫一扫
分享
社区描述
数据结构与算法相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章