Amazon Campus(2013-Sep-24)Question 1 / 2 (Amazon Campus(15): Clock wise walk)
来源:互联网 发布:国外手机安全软件 编辑:程序博客网 时间:2024/05/22 22:28
Question 1 / 2 (Amazon Campus(15): Clock wise walk)
Suppose we got a integer named size from input. size meet the rule:
size%2 ==1.
We use this size to build a square blocks, and we start from the center of block to go through all the array in clock wise. Please print the footstep sequence by number, please note we use asterisk to divide two neighbor numbers.
For example, we get size =3 from standard input, we should print following graph to standard output
7*8*9
6*1*2
5*4*3
For example, we get size =5 from standard input,we should print following graph to standard output
21*22*23*24*25
20*7*8*9*10
19*6*1*2*11
18*5*4*3*12
17*16*15*14*13
顺时针蛇形矩阵:
static String clockwise(int size) { String res = ""; int n,i,j,d = 0; n = size; int [][]a =new int[size+2][size+2]; a [1][n+1] = n*n+1; while(d<=(n-1)/2) { for(i = n-d ; i >= 1+d ; i--) a[1+d][i] = a[1+d][i+1] - 1; for(i = 2+d ; i <= n-d ; i++) a[i][1+d] = a[i-1][1+d] - 1; for(i = 2+d; i <= n-d ; i++) a[n-d][i] = a[n-d][i-1] - 1; for(i = n-1-d; i >= 2+d ; i--) a[i][n-d] = a[i+1][n-d] - 1; d++; } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(j!=n) res += a[i][j] + "*"; else res += a[i][j] + "\n"; } } return res; }
下面是逆时针的蛇形矩阵:
static String clockwise(int size) { String res = ""; int n,i,j,d = 0; n = size; int [][]a =new int[size+2][size+2]; a [n][n+1] = n*n+1; while(d<=(n-1)/2) { for(i = n-d ; i >= 1+d ; i--) a[n-d][i] = a[n-d][i+1] - 1; for(i = n-1-d ; i >= 1+d ; i--) a[i][1+d] = a[i+1][1+d] - 1; for(i = 2+d; i <= n-d ; i++) a[1+d][i] = a[1+d][i-1] - 1; for(i = 2+d; i < n-d ; i++) a[i][n-d] = a[i-1][n-d] - 1; d++; } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(j!=n) res += a[i][j] + "*"; else res += a[i][j] + "\n"; } } return res; }
- Amazon Campus(2013-Sep-24)Question 1 / 2 (Amazon Campus(15): Clock wise walk)
- Amazon Campus(2013-Sep-24)Question 2 / 2 (Amazon Campus(17):Find the differences of items in amazon)
- Amazon Campus(2013-Sep-22)Question 1 / 2 (Amazon Campus(5): completely inside interval)
- Amazon Campus(2013-Sep-22)Question 2 / 2 (Amazon Campus(9): MM-Chess)
- Amazon Campus(2013-Sep-25)
- Amazon Hiring Campus 2013
- 亚马逊在线技术笔试(Amazon Hiring Campus 2013 - Final 6)
- Campus
- Amazon
- Google 2013 campus recruitment
- Cisco 2013 Campus Hiring Position
- hdu 4804 Campus Design (2013 南京 轮廓线dp)
- Amazon云产品介绍(2) - Amazon SimpleDB
- Amazon云产品介绍(1) - Amazon EC2
- PAT练习(1)-1006 Cars on Campus
- 大学英语口语(Week 1)【Hometown & Campus life】
- Amazon Simple Queue Service(Amazon SQS)
- In Campus
- c# 判断一个文件是否正在被使用
- 喜得贵子新剧将播 霍思燕双喜临门
- 教你如何迅速秒杀99%的海量数据处理面试题(转)
- Linux gdb调试器用法全面解析
- WPF 可以自定义字段的Treeview
- Amazon Campus(2013-Sep-24)Question 1 / 2 (Amazon Campus(15): Clock wise walk)
- otg
- [官方教程] Firefly 介绍文档!
- Android+Unity3D简单的物体运动
- WPF 自定义柱状图
- UVA 11375 - Matches (数学——递推)
- 4.6
- SetProcessWorkingSetSize 和内存释放
- STL的Deque介绍