This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 最近参加了一个面试考试,其中考到几道关于算法的题目,感觉没答好,
所以拿出来跟大家请教请教.1. 设想有N个字母,请编个算法写出所以的组合
比如 N=3, 有 a, b, c三个字母,则组合是ab,ac,bc,abc.
当N=4, 则有a,b,c,d四个字母,组合为 ab,ac,ad,bc,bd,cd,abc,abd,bcd.
2. 一句话,比如 “I love this game”, 编个算法把这句话变为“game this love I”.
要求除了用一个变量外不能再占用别的内存空间。
-swang106(future);
2006-9-20
{299}
(#3218610@0)
-
第一个算法是垃圾,不多说了。第二个的诀窍是group flipping:先是整个句子flip,然后是每个单词flip。
-skywriting(天书);
2006-9-20
(#3218630@0)
-
P1 can be easily resolved with a recursive function; P2 only need a loop.
-polya(EasyWave);
2006-9-20
{636}
(#3218718@0)
-
2, 先是整个句子flip,然后是每个单词flip
-ice(Latino Caribo);
2006-9-20
(#3218814@0)
-
多谢各位,我想问一下大家平常都怎么研究这些算法的
有什么书籍或者资料可以推荐吗?
-swang106(future);
2006-9-20
(#3219014@0)
-
google
-ice(Latino Caribo);
2006-9-20
(#3219082@0)
-
2.I think the purpose is to test your knowlege of using double-linked list
-sunstar888(sunstar123);
2006-9-25
(#3228042@0)
-
i don't think so.
-ice(Latino Caribo);
2006-9-25
(#3228049@0)
-
第一题我以前做过,链接
-binghongcha76(一只大猫);
2006-9-25
(#3228127@0)
-
第二题更简单吧,不知这样行不行,只用了一个临时变量 i, 没用第二个变量,C#string xx = "i love this game";
for (int i = xx.Split(' ').Length - 1; i >= 0; i--)
{
Console.Write(xx.Split(' ')[i] + " ");
}
-binghongcha76(一只大猫);
2006-9-25
{156}
(#3228152@0)
-
you are really not on the right track at all. Usually, this kinda questions aim at testing whether people can think in a programmatical way.You really needs to think over these questions in algorithm patterns instead of benefitting from .NET features or STL. Though, in the really work, ,NET features and STL do help make things easier.
In the extreme case, the interviewers can simply stop you by asking you not to use .NET features or they even ask you implement Split().
-ice(Latino Caribo);
2006-9-25
{337}
(#3228183@0)
-
俺知道你的意思,但只用一个变量......这是比较难(如果把循环内的临时变量也算上的话)
-binghongcha76(一只大猫);
2006-9-25
(#3228286@0)