s*********d 发帖数: 2406 | 1 contrator的职位 面了基本上 6小时中间吃饭。
题估计也没什么好说的, 都是常见题,有关hash的。排序的。
表倒转的。
就一题,值得说一下。
有 一个 file 每行都是
http://google.com?=p=XXXXtemp=YYYYtest=ZZZZ
XXXX
YYYY
ZZZZ
是具体内容 算是。*
把每行的pattern 提取出来存起来。
要求 不重复的值去掉
并且 打印这个的所有组合。比如 有 xxx=atrix, s4
YYY= 340,260, ZZZ= blue,green
新组合是 atrix340blue 等。
问题 :
1. regex 如何很好的得这几个pattern来。
我用 “P=.*temp" 和 ”p=.*test" and "p=.*\n"
来分,个人觉得好像连pattern 都错了。
再用 substring。 本人regex 不熟。
2.3哥 要求 这个每行的pattern一起传到一个string里
再计算,我没想出来好的方法来得到所有的组合。
用 emurate方法 ?
我这部分得到的 string 用 split(“ ”)
分别存在3 个 hashset (自动解决重复问题);
之后 用了 O(n^3) 的算法。
主要没时间了。
他就 ok。
跟manager吃饭的时候,感觉不错。 他还说做的好转full time。
最后面完说要收集组员的反馈,说good luck。没有什么问题吧。 | h*******7 发帖数: 268 | | u*****o 发帖数: 1224 | | z****e 发帖数: 54598 | | c********p 发帖数: 1969 | | s*********d 发帖数: 2406 | 6 完成第一部分,regex好像很难,我google了一堆好像没有perfect方案
现在这个也很占内存
public HashSet readfromfile(String filename) {
HashSet plist=new HashSet() ;
try {
File file = new File(filename);
if (file.exists()) {
BufferedReader input = new BufferedReader(new FileReader(
file));
String line = null;
while ((line = input.readLine()) != null) {
StringBuffer paralist=new StringBuffer () ;
int val=line.indexOf("?") ;
if (val>-1){
String result=line.substring(val+1) ;
String[] Params=result.split("&") ;
for (String para:Params){
String[] temp=para.split("=") ;
paralist.append(temp[1]+" ") ;
}
}
;
plist.add(paralist.toString()) ;
}
}
} catch (IOException e) {
} return plist ;
} | s*********d 发帖数: 2406 | 7 继续 ,
public HashSet combination(HashSet list) {
HashSet first = new HashSet();
HashSet second = new HashSet();
HashSet three = new HashSet();
for (String temp : list) {
String[] tl = temp.split(" ");
first.add(tl[0]);
second.add(tl[1]);
three.add(tl[2]);
}
// start combin
String[] a = first.toArray(new String[first.size()]);
String[] b = second.toArray(new String[second.size()]);
String[] c = three.toArray(new String[three.size()]);
first=null ;
second=null ;
three=null ;
pos = new int[3];
enumerate(a, b, c, 0, a.length);
return result;
}
private void enumerate(String[] a, String[] b, String[] c, int i, int n)
{
// TODO Auto-generated method stub
if (i == 3) {
process(a, b, c);
return;
}
for (int p = n-1; p >= 0; p--) {
enumerate(a, b, c, i + 1, n);
pos[i] = p;
}
}
private void process(String[] a, String[] b, String[] c) {
// TODO Auto-generated method stub
StringBuffer templist=new StringBuffer();
templist.append(a[pos[0]]);
templist.append(b[pos[1]]);
templist.append(c[pos[2]]) ;
result.add(templist.toString()) ;
} | u*****o 发帖数: 1224 | 8 欣赏mm的认真,面完了还一定把题做出来,有头有尾。。这点精神就很难得啊。。 | s*********d 发帖数: 2406 | |
|