由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - javascript
相关主题
a question of perlArray in C
Go adopts JavaScript’s idea of semicolon insertionWhy Avoid array indexing. Use pointers.
Python:请问如何把list变成structured array。大侠进来看看这个问题
java 里可以插入linux command吗? (转载)问个程序问题
perl 问题Perl求助
perl array|hash question关于shared pointer的问题
JHQ的一道指针题。谁给解释一下这个c question
请看看这个Perl random sampling code 有什么问题,C++里get array size的问题 (转载)
相关话题的讨论汇总
话题: group话题: javascript话题: letters话题: file话题: so
进入Programming版参与讨论
1 (共1页)
r*******y
发帖数: 1081
1
【 以下文字转载自 Java 讨论区 】
发信人: romancity (山顶一枝草), 信区: Java
标 题: javascript
发信站: BBS 未名空间站 (Mon Oct 3 13:28:42 2011, 美东)
I have a file 1.txt
//1.txt
A B
B C
D E
E F
G H
I J
two letters in each line are in same group. So for the file above
A B C is in one group
D E F is in second group
G H is in third group
I J is in the fourth group
I need to use javascript to get the output below:
There are 4 groups:
group 1: A, B, C
group 2: D, E, F
group 3: G, H
group 4: I, J
How to write the javascript code ? Thanks a lot
X****r
发帖数: 3557
2
You sure you want to use JavaScript? Which environment you're
running JS in? Say, how do you read a file?

【在 r*******y 的大作中提到】
: 【 以下文字转载自 Java 讨论区 】
: 发信人: romancity (山顶一枝草), 信区: Java
: 标 题: javascript
: 发信站: BBS 未名空间站 (Mon Oct 3 13:28:42 2011, 美东)
: I have a file 1.txt
: //1.txt
: A B
: B C
: D E
: E F

r*******y
发帖数: 1081
3
thanks a lot. I read the homework again and find that I can use any language.
I may try linux shell script

【在 X****r 的大作中提到】
: You sure you want to use JavaScript? Which environment you're
: running JS in? Say, how do you read a file?

i*****o
发帖数: 1714
4
用node.js,这个东西可以替代很多perl,bash在做的事。现在要自己下载,估计以后
的linux都会包括吧。

【在 X****r 的大作中提到】
: You sure you want to use JavaScript? Which environment you're
: running JS in? Say, how do you read a file?

a***y
发帖数: 2803
5
用perl挺好的,读入一行后,用split(' ',$myline)把行分成2份放进一个array,然后比
较上一个array的第二个元素和这一个array的第一个元素是否相等,if yes,合并成一个
array.

【在 r*******y 的大作中提到】
: thanks a lot. I read the homework again and find that I can use any language.
: I may try linux shell script

r*******y
发帖数: 1081
6
A B
C B
in this case A, B, C are also in same group
I think the time complexity is a big problem here.
I want to use c++ now

【在 a***y 的大作中提到】
: 用perl挺好的,读入一行后,用split(' ',$myline)把行分成2份放进一个array,然后比
: 较上一个array的第二个元素和这一个array的第一个元素是否相等,if yes,合并成一个
: array.

t****t
发帖数: 6806
7
http://en.wikipedia.org/wiki/Disjoint-set_data_structure
i dunno why you focus on programming language while dealing with this
typical algorithm problem

【在 r*******y 的大作中提到】
: A B
: C B
: in this case A, B, C are also in same group
: I think the time complexity is a big problem here.
: I want to use c++ now

i*****o
发帖数: 1714
8
There are only 27 letters, where is the time complexity? All you need is to
start eith 27 empty pointers. The time for this operation is most likely O(n
).

★ 发自iPhone App: ChineseWeb - 中文网站浏览器

【在 r*******y 的大作中提到】
: A B
: C B
: in this case A, B, C are also in same group
: I think the time complexity is a big problem here.
: I want to use c++ now

r*******y
发帖数: 1081
9
thanks a lot.
The problem is that it is not just about letters. A, B, C stands names
and the data may be huge

to
(n

【在 i*****o 的大作中提到】
: There are only 27 letters, where is the time complexity? All you need is to
: start eith 27 empty pointers. The time for this operation is most likely O(n
: ).
:
: ★ 发自iPhone App: ChineseWeb - 中文网站浏览器

t****t
发帖数: 6806
10
i thought the number of letters is 26, no?...

to
(n

【在 i*****o 的大作中提到】
: There are only 27 letters, where is the time complexity? All you need is to
: start eith 27 empty pointers. The time for this operation is most likely O(n
: ).
:
: ★ 发自iPhone App: ChineseWeb - 中文网站浏览器

i*****o
发帖数: 1714
11
and I always thought it's 27!
And I proved that using gdb:
(gdb) p 'z'-'a'
$2 = 25
Now we know gdb is the best tool ever! I found no other way in the world to
give me the number of alphabets in just one line of code.

【在 t****t 的大作中提到】
: i thought the number of letters is 26, no?...
:
: to
: (n

i*****o
发帖数: 1714
12
Then you are right, javascript is not suitable for this.

【在 r*******y 的大作中提到】
: thanks a lot.
: The problem is that it is not just about letters. A, B, C stands names
: and the data may be huge
:
: to
: (n

t****t
发帖数: 6806
13
didn't it print 25? so it's really 25?

to

【在 i*****o 的大作中提到】
: and I always thought it's 27!
: And I proved that using gdb:
: (gdb) p 'z'-'a'
: $2 = 25
: Now we know gdb is the best tool ever! I found no other way in the world to
: give me the number of alphabets in just one line of code.

i*****o
发帖数: 1714
14
haha, you cant trick me on this one, its really 26:)

★ 发自iPhone App: ChineseWeb - 中文网站浏览器

【在 t****t 的大作中提到】
: didn't it print 25? so it's really 25?
:
: to

1 (共1页)
进入Programming版参与讨论
相关主题
C++里get array size的问题 (转载)perl 问题
C++ Function Pointer Array 的问题perl array|hash question
zero-sized array vs pointerJHQ的一道指针题。
array和pointer在作为函数返回时有啥区别 (C)请看看这个Perl random sampling code 有什么问题,
a question of perlArray in C
Go adopts JavaScript’s idea of semicolon insertionWhy Avoid array indexing. Use pointers.
Python:请问如何把list变成structured array。大侠进来看看这个问题
java 里可以插入linux command吗? (转载)问个程序问题
相关话题的讨论汇总
话题: group话题: javascript话题: letters话题: file话题: so