muduzhu

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  2 随笔 :: 4 文章 :: 4 评论 :: 0 引用

2010年7月5日 #

到新单位快两月了,趁还记得面试时的一些题目,总结并记下,以资园友参考!

1.判断单链表是否有环,这题太经典了,有好几家公司面试问到这题。

2.数字舍入,精确到0.05,即五分钱,如,12.34  舍入后 12.35、12.36舍入后12.40、

12.30舍入后12.30、12.40舍入后12.40。

3.请用一个循环将乘法表打印出来。

4.一个M*N的方格,里面含有多少个矩形?如2*2的方格,则含9个矩形。

5.现在A有方法MethodA,B继承A,并声明new MethodA,C继承B,也声明new MethodA,

请问如何在C类中访问A类中的MethodA?(不要写个代码来测试,思考下,面试时可没计算机)

6.请写一个方法,将字符串翻转,如Hello,World!翻转为!World,Hello 。

7.如何在栈里声明对象?(.net)

8.单链表,如何找到中间节点?如何找到倒数第N个节点?

9.如何判断一个数是否为2的n次方?效率越高越好。

10.请用多线程实现生产消费者模型。

未完待续...

 

先付上答案:

1.单链表找环的解法有两个思路,一个是保存遍历过的指针,然后进行查找;一个是快慢指针的方法。

2.这道题是去一家做金融行业软件的公司面试的题目,解法如下:

 

代码
 1         static decimal Floor(decimal d)
 2         {
 3             decimal hundredD = decimal.Multiply(d, 100M);
 4             decimal intD = decimal.Floor(hundredD);
 5             decimal diff = hundredD - intD;
 6             decimal result = decimal.Zero;
 7             if (decimal.Equals(diff, decimal.Zero))
 8             {
 9                 result = intD;
10             }
11             else if (diff <= 0.5M)
12             {
13                 result = intD + 0.5M;
14             }
15             else if (diff > 0.5M)
16             {
17                 result = intD + 1M;
18             }
19 
20             return decimal.Divide(result, 100M);
21             
22         }

 

3.

 

代码
        static void PrintMultiplyTable()
        {
            
int line = 1;
            
for (int i = 1; i <= line && line <= 9;)
            {
                Console.Write(
"{0} * {1} = {2}\t", i, line, i * line);
                
if (i == line)
                {
                    line
++;
                    i 
= 1;
                    Console.WriteLine();
                }
                
else
                {
                    i
++;
                }
            }
        }

 

4.?

5.?

6.这个应该没啥考的,就看你写代码是否工整,检查边界。

7.未解,我回答的是不能在栈里什么声明对象,应该都是托管对象,应该只能在堆上分配对象。可是他问出这个问题,着实有些疑惑!同行们可一起深究下!

8.这道题的思想是快慢指针法,查找中间节点,只要快指针每走两步,慢指针跟上一步就行能找到。倒数第N个则快指针先走N步,然后慢指针开始移动。

9.

static bool is2Exp(int num)
{
    
return (num & (num - 1)) == 0;
}

 

10.干活了,晚上续上。

posted @ 2010-07-05 15:02 大黄牛 阅读(1023) 评论(4) 编辑

2010年4月9日 #

http://perl.about.com/od/cgiprogramminginperl/a/020905.htm

How to identify a browser

HTTP_USER_AGENT is one of the 19 CGI environment variables defined by The National Center for Supercomputing Applications (NCSA). It is used to identify the user agent that the client is using when a CGI script is accessed from a web page.

What is a user agent?

A user agent is the application a client uses to access a web page, which may be a browser, a mobile device or service such as AvantGo, or web crawlers, among other things. HTTP_USER_AGENT is the CGI environment variable that is generated to identify the user agent, and this information may be used to good effect if you want to present specific pages to your users based on what they're using to view the page. It's also handy if you want to use the robots.txt file to exclude a crawler from your site, or particular sections of your site.

What does the HTTP_USER_AGENT string look like?

Typically, the information included in HTTP_USER_AGENT includes the name of the client application and version, the operating system used by the host, and the language. Other information may also be included, such as a URL or email address.

Some of the strings identifying browsers are a little confusing, and this stems from the struggle for browser dominance. As one browser gains popularity, web sites may cater to it, or exclude other browsers entirely, even though they may handle complex pages being sent to it. Therefore, some browsers send a spoofed or cloaked string so that the page content will be retrieved properly.

For example, early versions of Internet Explorer sent an HTTP_USER_AGENT string identifying it as Mozilla, which was then used by Netscape Navigator. Now that Internet Explorer has gained dominance, some newer browsers follow in the same tradition, identifying themselves as Mozilla, MSIE, and the correct browser name.

Here are some examples 
=== 
Internet Explorer 
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0) 
Mozilla/4.0 (compatible; MSIE 4.0 Crawler; Windows 95) 

Netscape Navigator 
Mozilla/4.0b1 (Win95; I) 
Mozilla/3.01Gold (Macintosh; U; PPC) 
===

How can I know the correct user agent?

The easiest way to have the correct user agent at your fingertips is to use a compiled list. A good one is presented by Zytrax, and Siteware Technologies.

posted @ 2010-04-09 22:32 大黄牛 阅读(912) 评论(0) 编辑