转: From twitter

帝都很多文绉绉的地名其实原本乡土得很。甘井胡同→干井胡同;辟才胡同→劈柴胡同;礼士路→驴市胡同;光彩胡同→棺材胡同;秀水街→臭水街;雅宝路→哑巴胡同;中关村→中官村→中官(太监)坟。
Posted in Uncategorized | Leave a comment

最近遭遇三大骗

第一骗 01095500 阳光保险电话推销

第二骗 17996 铁通上门推销
第三骗 KFC
请广大群众小心上网晓习 提前预防
Posted in Life | Leave a comment

Product of everything except current

Product of everything except current
Write a function that takes as input two integer arrays of length len, input and index, and generates a third array, result, such that:
result[i] = product of everything in input except input[index[i]]
Specifically:
void everythingExcept(int len,                // in parameters
                      int *input, int *index,
                      int *result             // out parameter
                     );
For instance, if the function is called with len=4, input={2,3,4,5}, and index={1,3,2,0}, then result will be set to {40,24,30,60}.
IMPORTANT: Your algorithm must run in linear time.
If you would like to implement the solution in C#, consider the following signature:
public int[] everythingExcept(int[] input, int[] index);

Answer:
For example, if we have 4 elements in input array, we could calculate product like this:
Step1         a1 a2 a3 a4
                 1  *   *  *
                 *  *   *  1
—————————
Step 2     a1   a2  a3 a4
              1    *   *   *
              1*a1 *   *   *
              *    *   *   a4*1
              *    *   *   1
——————————
Step 3     a1    a2  a3 a4
              1     *   *   *
              a1    *   a3*a4
              a1*a2    *   a4
              *     *   *   1
——————————
Step 4   a1    a2  a3 a4
           1     a2*a3*a4
           a1    *   a3*a4
           a1*a2    *   a4
           a1*a2*a3     1

code written in notepad:
public int[] everythingExcept(int[] input, int[] index)
{
    // null, empty, index range check
    int[,] pairs = new int[input.Length,2];
    pairs[0,0] = 1;
    for(int i = 1; i< input.Length ; i++)
    {
        pairs[i,0] = pairs[i-1,0] * input[i-1];
    }
    pairs[input.Length-1,1] = 1;
    for(int i = input.Length – 2; i>=0; i–)
    {
        pairs[i,1] = pairs[i+1,1] * input[i+1];
    }
    int[] result = new result[input.Length];
    for(int i = 0; i < result.Length; i++)
    {
        reuslt[i] = pairs[index[i],0] * pairs[index[i],1];
    }
    return result;
}
NOTE: we can’t calculate product of all elements then divide each element, because product of all elements might be great than Int32.MaxValue but result array don’t.

Posted in 计算机与 Internet | Leave a comment

修鼠标记

今天刚把一贼漂亮贼漂亮的鼠标送人,回到家想起了扔在旧物堆里的IE4.0,再看看摆在电脑旁的滚轮鼠标,不由感慨万千。IE4.0是被一鼠标杀手游戏活生生点坏的(Caution: 不要以为好鼠标玩这类游戏很爽,等玩坏了就后悔了),左键间歇性无反应。抱着破罐子破摔的想法决定尽最后的努力修一下。IE4.0还不真好拆,网上的文章只说了隐藏的螺丝的位置,却没有说前部是怎么卡住的。用了点猛劲把它掰开,直接按微动还是很起用的,感觉不是电路毛病。所以打算在按键底下垫点东西,于是粘上两片胶带纸,合上上盖,My IE4.0 is back
Posted in 计算机与 Internet | 3 Comments

Powershell script that grap books list form www.free-ebooks-download.org

Don’t use it too much.
 
$wc = New-Object System.Net.WebClient
$homePage = $wc.DownloadString("http://www.free-ebooks-download.org/")
$regex = [regex]’http://www.free-ebooks-download.org/free-ebook/%5B-\.\w/\s]*’
$categoryMatches = $regex.Matches($homePage)
foreach($cm in $categoryMatches)
{
    $categoryPage = $wc.DownloadString($cm.Value);
    $pageRegex = [regex]’&nbsp;<a href="([-\w.]+)">’;
    $pageMatches = $pageRegex.Matches($categoryPage);
    foreach($pm in $pageMatches)
    {
        $bookPage = $wc.DownloadString($cm.Value + $pm.Groups[1].Value);
        $bookRegex = [regex]’class="main" href="[^"]+" title="([^"]+)">’;
        $bookMatches = $bookRegex.Matches($bookPage);
        foreach($bm in $bookMatches)
        {
            echo $bm.Groups[1].Value
        }
    }
}
Posted in 计算机与 Internet | Leave a comment

A better one

int hourMinuteHandInRight = 0;

int hourMinuteHandInLeft = 0;

int interval = 60;

int rightHand = 180 – interval;

int leftHand = 540 – interval;

while (hourMinuteHandInRight < 12 && hourMinuteHandInLeft < 12)

{

rightHand += interval;

if (rightHand == 660)

{

rightHand = 0;

hourMinuteHandInRight++;

}

Console.WriteLine("{0}:{1}", hourMinuteHandInRight, (int)(rightHand / 11));

hourMinuteHandInRight++;

leftHand += interval;

if (leftHand >= 660)

{

hourMinuteHandInLeft++;

leftHand = 0;

}

Console.WriteLine("{0}:{1}", hourMinuteHandInLeft , (int)(leftHand / 11));

hourMinuteHandInLeft++;

}

Posted in Uncategorized | Leave a comment

Write a function to give out all the time (hour:minute) that the angle between minute hand and hour hand on a clock is 90 degree.

static void Main(string[] args)

{

for (int h = 0; h < 12; h++)

{

double m = 1.0;

double angle = 1.0

if (h < 9)

{

m = 1.0*(60 * h + 180) / 11;

angle = (m – h * 5 – m / 12) * 6;

Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);

}

if (h > 9)

{

m = 1.0 * (60 * h – 540) / 11;

angle = (h * 5 + m / 12 – m) * 6;

Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);

}

if (h < 3)

{

m = 1.0 * (60 * h + 540) / 11;

angle = (m – h * 5 – m / 12) * 6;

Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);

}

if (h > 3)

{

m = 1.0 * (60 * h – 180) / 11;

angle = (h * 5 + m / 12 – m) * 6;

Console.WriteLine("{0}:{1} {2}", h, (int)m, angle);

}

}

}

Posted in 计算机与 Internet | Leave a comment