Topic: 今天看见一道不错的题目....................... |
Print this page |
1.今天看见一道不错的题目....................... | Copy to clipboard |
Posted by: aiff Posted on: 2004-09-30 21:46 1 3 6 10 2 5 9 13 4 8 12 15 7 11 14 16 这个程序用JAVA怎么写啊 呵呵 |
2.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: why Posted on: 2004-09-30 23:24 { 请尽量用准确的文字描述作为标题 } What are you talking about? |
3.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: justin_here Posted on: 2004-09-30 23:39 左下到右上依序排列? |
4.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: aiff Posted on: 2004-10-01 00:31 结果输出为 1 3 6 10 2 5 9 13 4 8 12 15 7 11 14 16 的程序 怎么写?有什么新方法 |
5.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: sankxuan Posted on: 2004-10-01 14:51 public class IntQueue { public static void main(String[] args) { int xIncrease = 1; int yIncrease = 1; for (int i = 0; i < 4; i++) { xIncrease = yIncrease + i; for (int j = 0; j < 4; j++) { xIncrease += j; int printNum = j + xIncrease; System.out.print(printNum + " "); } yIncrease ++; System.out.print("\n"); } } } |
6.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: aiff Posted on: 2004-10-01 16:13 楼上的 你的code不对啊~~你检查检查 |
7.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: sankxuan Posted on: 2004-10-01 20:52 对不起,看错题目意思了,改了改
|
8.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: dorrenchen Posted on: 2004-10-02 00:10
|
9.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: kulatasana Posted on: 2004-10-20 22:18 int size = 4; int num[size][size]; int n = 1; for(int i = 0;i < size;i++) for(int j = 0;j < i+1;j++) for(int k = 0;k < =j;k++){ num[k][j-k] = n; num[size - k-1][size-j+k-1] = size*size-n; n++; } 应该没错,具体没调试,有错别怪我哦~~~ 不过就算法应该没问题,循环次数也尽量做到最少了(1+size)*size/2次. |
10.Re:今天看见一道不错的题目....................... [Re: aiff] | Copy to clipboard |
Posted by: kulatasana Posted on: 2004-10-20 22:51 上面的代码似乎有点问题,,不小心多+了个循环,我的错,改过!! int size = 4; int num[size][size]; int n = 1; for(int i = 0;i < size;i++) for(int k = 0;k < i+1;k++){ num[k][i-k] = n; num[size-k-1][size-i+k-1] = size*size+1-n; n++; } 不知道对不 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |