|
查看: 1285|回复: 12
|
Java Data Structure..紧急
[复制链接]
|
|
|
弱弱的问一下, 请问怎样能够抓到array 里面的单独号码?就比如说user 输入了6个digit 的number,456789
如果正常来说456789会存在array的第一个位子, 【0】,但我现在是想用fold shift 来决定他存在的位子,我要怎样捉到
array【0】="456789" 里面的 单独数字 ?就是说分开成"4","5","6","7","8","9",
45+67=112
我最后是将这个456789存在【112】的位子 |
|
|
|
|
|
|
|
|
|
|
发表于 16-10-2011 08:14 PM
|
显示全部楼层
123456 % 10 = 6
12345 % 10 = 5
1234 % 10 = 4
123 % 10 = 3
12 % 10 = 2
1 %10 = 1
醬瓜 |
|
|
|
|
|
|
|
|
|
|
发表于 17-10-2011 05:31 PM
|
显示全部楼层
弱弱的问一下, 请问怎样能够抓到array 里面的单独号码?就比如说user 输入了6个digit 的number,456789
如 ...
风之女神 发表于 16-10-2011 05:27 PM 
感觉用 linkedlist 就可以 settle 这个问题了  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-10-2011 05:50 PM
|
显示全部楼层
感觉用 linkedlist 就可以 settle 这个问题了
兔仙人 发表于 17-10-2011 05:31 PM 
还有其他方法吗?除了linked list. |
|
|
|
|
|
|
|
|
|
|
发表于 17-10-2011 05:58 PM
|
显示全部楼层
还有其他方法吗?除了linked list.
风之女神 发表于 17-10-2011 05:50 PM 
HASHMAP 可以吗  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-10-2011 05:59 PM
|
显示全部楼层
HASHMAP 可以吗
兔仙人 发表于 17-10-2011 05:58 PM 
这个当然可以, 只是我不懂怎样写而已。. |
|
|
|
|
|
|
|
|
|
|
发表于 17-10-2011 06:24 PM
|
显示全部楼层
这个当然可以, 只是我不懂怎样写而已。.
风之女神 发表于 17-10-2011 05:59 PM 
为什么只算 4567 ?  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-10-2011 06:52 PM
|
显示全部楼层
为什么只算 4567 ?
兔仙人 发表于 17-10-2011 06:24 PM 
erm..只是一个例子而已。 我主要目的还是要存456789在另一个index位子, 通常来说第一个data 会存在【0】 |
|
|
|
|
|
|
|
|
|
|
发表于 17-10-2011 07:02 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-10-2011 07:11 PM
|
显示全部楼层
Did you learn the hashing method before ? There have one kind of method to arrange the data.
The Solution i want is call fold shift, mean that when a student key in a 6 digit(static range) number, it will calculate and store in other seat.
the student had key in :456789, we separate the number in individual number : "4","5","6","7","8","9"
and catch the number. normally the first data in array will store in 【0】location . but now i decide to change the save location, so i need to follow the number the student key in and decide where it store the location.
for the fold shift method , 456+789= 1245, mean when the final result , the 456789 will store in this 【1245】index location. the size of array is define by self. |
|
|
|
|
|
|
|
|
|
|
发表于 19-10-2011 03:35 PM
|
显示全部楼层
Did you learn the hashing method before ? There have one kind of method to arrange the data.
The S ...
风之女神 发表于 17-10-2011 07:11 PM 
Hmmm , I helped to do some research here.
https://github.com/steshaw/playground/blob/238e68a7d343a87a8391acc62a77c6cacf9f1c6c/java/fj/Fold.java
So , what you need to do is ,
1) You have the key , so distribute your key the several part (as you like) -> i will use substring and convert to number
2) After then store them into List or Array
3) Using above coding , run through the func1 , change the *= to +=
4) Then you can get your expected result liao 
中文 |
|
|
|
|
|
|
|
|
|
|
发表于 19-10-2011 06:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 20-10-2011 01:15 AM
|
显示全部楼层
已經有中文pun,不用特地加一個“中文”在ending吧?
vxion 发表于 19-10-2011 06:29 PM 
已经找到方法solve problem 了, 用menthod % |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|