顯示廣告
隱藏 ✕
看板 rikaka
作者 rikaka (rikaka)
標題 Re: 面試考題整理
時間 2012年03月27日 Tue. PM 02:21:00


http://antontw.blogspot.com/2008/02/yahoo_19.html

1. What is difference between GET/POST?
Ans:

GET method put a long url string to web server. It is simple to be used by click and click but the content is limited and the value is easily effected by the browser.

POST method can handle data with multiple types, and CGI reads data stream from stdin as long as it posts data. However, it is so convenient and direcy just like GET.

2. How do you keep state using Web forms?
Ans:

One is to add input box into web content, simply set the type to be "hidden" and put the same value.one is to add a section into javascript, use createElement to add input box into form object.It depends on the requirement of web site. The former is simple and better to be maintained but less security.


3. Given a line of text $string, how do you use "regular expression" to strip all html tags from it?
Ans:

#!/usr/bin/php
preg_replace("/<[^>]*>/","",$string);


4. Describe UNIX IPC's ?
Ans:
  IPC is a solution to inter-process communication on unix-like system. Generally, it includes pipes, FIFOS, sockets, and streams. And System V IPC means common kernel entry point for the IPC calls for messages queues, semaphores, and shared memory. Except of System V IPC , most forms of IPC are half-duplex. Data flows only in one direction. All three forms of System V IPC have built-in limits that we may encounter. Most of these can be changed by reconfiguring the kernel.


5. Write an algorithm to reverse the order of words within a string, i.e. given char *string = "The cow jumped over the moon" becomes "moon the over jumped cow The". Use as little memory space as possible, time is not a factor.
Ans:

#include "stdio.h"
#include "string.h"

void
ReverseWord(char *begin,char *end)
{
if ((begin==NULL) || (end==NULL)) return;
if (end < begin) return;
char *q = begin;
char *p = end;
char c;
while(q < p)
{
c = *q;
*q = *p;
*p = c;
q++;
p--;
}
}

int
main()
{
char str[] = "This is a test";
ReverseWord(str, str+(strlen(str)-1));
char *p,*q;
p = q = str;
while(*p!=0)
{
if (*p==' ')
{
ReverseWord(q,p - 1);
while((*p==' ')&&(*p!=0))
p ++;
if (*p!=0)
{
q = p;
p++;
}
} else {
p++;
}
}
ReverseWord(q,p - 1);
printf("%s\n",str);
return 0;
}



6. In C, please write a program to print out an integer number 12345 without using printf?
Ans:

  fprintf(stdout, "%d\n", 12345);


7. Given an array in

PHP :

$ list = array('apple'=>300, 'orange'=>150, 'banana'=>100, 'mango'=>330)

Perl :

%list = ( 'apple'=>300, 'orange'=>150, 'banana'=>100, 'mango'=>330 ) ;

C++:

typdef map< string, int, less> array_type ;

array_type m;

m.insert(array_type::value_type("apple", 300));

m.insert(array_type::value_type("orange", 150));

m.insert(array_type::value_type("banana", 100));

m.insert(array_type::value_type("mango", 330));

Please choose one language above and write a programe to sort the array by

the order of key and value respectively with your own sorting algorithm.

Please don't use the sorting functions provided by language.


Ans:
  // vim:set fdm=indent ts=2 ai et sts=2 sw=2 tw=0:
function myarray_remove($list,$key)
{
$orig = $list;
$len = count($list);
$i=0;
foreach ($list as $k => $v)
{
if ($k==$key) { $tk=$k; $ti=$i; }
$i++;
}
$temp = array_merge(array_slice($orig,0,$ti),array_slice($list,$ti+1,$len-$ti-1));
return $temp;
}

function value_get_biggest($list,$sortbyvalue=true)
{
foreach ($list as $k => $v)
{
if (!$sortbyvalue)
{
if (ord($k)>ord($tk))
{
$tv = $v;
$tk = $k;
}
} else {
if ($v>$tv)
{
$tv = $v;
$tk = $k;
}
}
}
return array($tk=>$tv);
}

function mergesort($list,$sortbyvalue)
{
$one = value_get_biggest($list,$sortbyvalue);
$list = myarray_remove($list,key($one));
if (count($list)>0)
{
$temp = mergesort($list,$sortbyvalue);
$temp = $temp + $one;
return $temp;
} else {
return array(key($one)=>$one[key($one)]);
}
}

$list=array('apple'=>300, 'orange'=>150, 'banana'=>100, 'mango'=>330);
$list = mergesort($list,false);
print_r($list);



8. What sort of things do you need to worry about from a security perspective when writing a web application?
Ans:


 (0) Think before we leap.
The application began when the project manager start to write the policy, specification/(even rules in detail) in design time, but the programmers may be not well-communicated. The disaster begins when nobody knows what is the core value in the application service.

(1) Make it simple and stupid.
After the project manager wrote the policy and rules, I think that it is easier to maintain when its components are more simple. When it's easier to maintain the bugs inside are easier to be found.

(2) Version Control
It is not easy to find out where bugs begin at the first time, but it is easy to know what we did by the version control.

(3) Review, Monitor and Update
Code changes when a new skill is found, and sometimes the crackers find a entry that nobody ever take a look. But it really helps when we use a monitor software, inspector software, and update reminder.


--
※ 作者: rikaka 時間: 2012-03-27 14:21:00
※ 編輯: rikaka 時間: 2012-03-27 16:49:33
※ 同主題文章:
※ 看板: rikaka 文章推薦值: 0 目前人氣: 0 累積人氣: 315 
分享網址: 複製 已複製
guest
x)推文 r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇