'test'에 해당되는 글 1건

  1. 2008/06/03 야후! 홍콩 입사 시험 문제 (2)

내가 입사할때의 NHN의 시험문제와 거의 비슷한 수준의 난이도이다. (심지어 같은 문제도 있다. -_-)

아래 부터 문제와 나의 풀이이다.



C and C++:


Q1. What is wrong with the following code?

char a[256];

unsigned char x;

for (x=0; x< sizeof(a); x++) a[x]=0;


 

The loop ends with x has 256. but, x is never become 256. because unsigned char's max value is 255 (1 byte). The code will loop infinity.


 

Q2. A structure has an integer, a pointer and a char, how big is it?


 

In 32-bit environment, It is bigger than 5bytes.
"char" member is 1bytes and "integer" memeber is 4byte, But we can't know the size of a pointer. Because, it is determined by the type the pointer indicated.
So, the size of the struct will be determined by the pointer.


Q3. Implement the following function. It prints a string after replacing all occurrence of a substring with a char ‘*’. Both strings should be left unchanged after the function returns. Runtime efficiency and error checking are considered important.

    

void print_string_replace(char *string, char *substr)


 

void print_string_replace(char *string, char *substr) {
 int stringLength = strlen(string);
 int substrLength = strlen(substr);
 int i;
 char *result;
 char *tmp;

 if(substrLength > stringLength) {
  puts("substr must be shorter than string");
 }
 
 // make a local copy of string
 memcpy(result, string, stringLength);

 // find an occurrence
 tmp = strstr(result,substr);

 if(!tmp) {
  puts("substr is not present in string");
 } else {
  do {
   // replace occurrence to "*"
   for(i = 0; i < substrLength; i++) {
    tmp[i] = '*';
   }
  } while (tmp = strstr(result, substr));
  // print a result
  puts(result);
 }
}


Q4. Explain operator overloading in C++.


In C++, basic operators are defined by compiler. When you define a different operation for an operator by changing the standard parameter list, it is operator overloading. It can improve understandability and reduce maintenance costs.


Web/CGI:


Q1. I want to provide a personalised web page, which presents different

data to different users - what URL/CGI techniques can I use to

identify each user? What are the advantages and disadvantages of

each technique?


URL based :  Provided by web server.When a user enters a protected site, the server asks the web browser for authentication. Then, the browser asks user's name and password by a prompt, and it will be sent to web server. If given informations are valid, the user is authenticated, and then user can access server's location. This cycle is needed by each time of user requests.

  • advantages : simply implementation.
  • disadvantages : less security. overhead. bad UI.


CGI based : Most of CGI applications are set the session value to web browser. So, the client sends the information of authentication to the server once.  In addition, a CGI application can present different pages to different users, as long as they are authenticated.

  • advantages :more flexibility. can make more complex UI.
  • disadvantages : more complex development.

Q2. Assuming we had a continuous feed of data that was being piped into

site, and it needed to distributed to up to 10 different machines in

real time. Describe at least one method you would use?


There 3 methods I have. These are:


  • rsync : Run rsync as a daemon on each server. And, Deploy to each server by call the rsync command when the feed has been renewed.
  • NAS : If the NAS equipment is mount the directory has a feed to each servers using NFS, it will be automatically updated when feed has been renewed.
  • SAMBA  :SAMBA is similar to NAS. It become a equipment like NAS to run SAMBA daemon on the feed server. Each servers can mount use CIFS type. It would has very lower cost than NAS.


Perl:


Q1. Write a perl program to insert a white space before and after the occurrence of numeric string. The program read from standard input and writes to standard output. For example, Input: ‘aaaa1111bb22cc333’, Output: ‘aaaa 1111 bb 22 cc 333 ‘


 

foreach $char(split(//,<STDIN>)) {
    print $prev_char ne "" && $prev_char ne $char ? " $char" : $char;
    $prev_char = $char;
}

Q2. What does ‘my’ do? Is it the same as ‘local’


 They declare local variable. "my" creates private scope variable. "local" creates temporary copies of selected global variables.


Q3. Suppose I want to pass two arguments to a subroutine, both of which are

arrays. How do I do that without using global varialbe?


Perl supports a reference variable. You can make a reference to append "\" at first of subroutine's parameters when it is called. And, you can access it with "@" in subroutine.


Like this :


@arr1 = ('alpha', 'bravo');
@arr2 = ('chalie', 'delta');

mysub(\@arr1, \@arr2);

sub mysub {
 my ($myarr1, $myarr2) = @_;
 print("my arr1 : @$myarr1 \n");
 print("my arr2 : @$myarr2 \n");
}


PHP:


Q1. How do you serialize data in PHP?


It can be just calling "serialize()" function. "serialize()" can serialize to string all data type without resource. In object type, "serialize()" call "__sleep()" before serialize it.


Q2. What is the difference between a reference and a regular variable? How do you pass by reference & why would you want to?


 

If a regular variable is passed to function, it creates temporary copy on their block. It keeps the value in outside of function.

When a variable is passed by reference, the function it is being passed to can modify the variable.

You can pass by reference to add "&" on head of parameter in the function definition.

like this,

function foo(&$param) {

...

}


Q3. Assuming you have inserted a record in a MySQL table, which has an auto-increment column. How do you retrieve the generated value of that column?


 

PHP function : mysql_insert_id(), mysqli_insert_id(), PDO->lastInsertId()

SQL : select last_insert_id()




UNIX:


Q1. Detail what Unix tools you are experienced with and why you like

them?


yum/apt : Package manager. I am tired out to compile sources.

perl : Most of Unix machines have this. I prefer PHP.

ruby : Exprience agile development. Just for fun.

wget : Download via http/ftp. I use this for crawling.




Database:


Q1. Explain what is left join, right join and inner join?


Left/Right join returns all rows of first table and all matching rows from the next table. Not matched columns of next tables are set to NULL.

Inner join returns all matching rows. It does a full join.


Windows Related:


Q1. How will you create a window and have it show in the taskbar when the window is minimized ?


Hmm, I can't remember this exactly. 

Set the property that show in the taskbar when window is minimized to some class and register it.

And then, creates window....


Q2. What is the IUnknown interface and what functions does it provide? (C++)


I've been see it in visual basic before. But, I don't remember it. Just know that it is a COM interface.


Q3. You join a 3 person project which has been running for some time.

During your first week you notice that a piece of the project's VC++

code appears to be running slower than you would expect.

How do you confirm your suspicion?


I know that VC++ has profiling function. Simply, I can enable profiling option on the "Project Preference" menu (Probably.. I don't have the Visual Studio) and show it to them.


댓글을 달아 주세요

  1. Neon 2008/06/03 15:23  댓글주소  수정/삭제  댓글쓰기

    Q2. align에 대한 설명을 추가하셔야 할듯. 보통 char 1바이트를 4바이트로 align해서 총 12바이트로 나옵니다.
    Q3. malloc도 안하고 memcpy를 하면 당연히 runtime error가 나오겠죠? 그리고 input으로 "abcabcabc"와 "abcabc"가 주어졌을때 "******abc"가 아니라 "*********"로 바껴야되지 않을까요? 그런 의미에서 그건 좀 틀린듯.
    Perl Q1.
    저같으면
    $_=~ s/([0-9])([a-z])/\\1 \\2/g;
    $_=~ s/([a-z])([0-9])/\\1 \\2/g;
    를 쓰겠지만, 고수의 비법은 어떠할지 궁금하네요. 이건 ↓님께서 설명해주실듯.

  2. difro 2008/09/18 18:01  댓글주소  수정/삭제  댓글쓰기

    Perl Q1.
    #!/usr/bin/perl
    $_=<>;
    s/([0-9]+)/ \1 /g;
    print;
    이건 어떤가요. (그냥 지나가다..)