2009年11月21日

          世界十大最糟糕網站設計(中文翻譯)

               摘要: 你曾經打開過真正設計糟糕的網站,糟到你都覺得是自己手太賤么?我就非常“幸運”能看到一坨這種震撼人心的網站。下面這些是這些糟糕網站中最糟糕的。
          如果你是一個網頁設計師,趕快行動起來吧,趕緊給他們發郵件提供服務。
          如果你的網站不幸在這個名單中,也別覺得窩心,不過您最好還是考慮考慮重新設計一下網站比較好。。。  閱讀全文

          posted @ 2009-11-21 03:04 甜菜侯爵 閱讀(2220) | 評論 (3)編輯 收藏

          2009年11月17日

          世界十大最糟糕網頁設計

          鏈接如下:

          先放這里,現在沒有時間,等有空了把原文翻譯了貼過來。
          寫得還是蠻有意思的。http://www.blogstorm.co.uk/blog/top-10-worst-websites/

          posted @ 2009-11-17 01:18 甜菜侯爵 閱讀(268) | 評論 (0)編輯 收藏

          2009年11月7日

          用正則表達式取出去除html頁面中的tags

          這個就比較簡單了,正則式是 “<[^>]*>”,其表意為“以<開頭的,后續任意個不為>的字符,并以>結尾的字符串”
          這樣做的目的是為了獲得所謂plain的文本,方便下一步的處理。

          代碼如下:

          1    /**
          2     * Remove all "<>" tags in the text
          3     * @param tagText
          4     * @return the clean text without tags
          5     */

          6    public String removeTags( String tagText )
          7    {
          8        return tagText.replaceAll("<[^>]*>""");
          9    }

          posted @ 2009-11-06 22:19 甜菜侯爵 閱讀(202) | 評論 (0)編輯 收藏

          2009年11月5日

          用正則表達式提取網頁中的鏈接

          個人感覺效率肯定還能進一步提高。。。。
          不過實在是對正則不是太熟悉,只好暫時這樣了。

          代碼如下:

           1    /** The regex for search link with the tag "a" */
           2    private final String A_REGEX = "<a.*?/a>";
           3    /** The regex for search url with the tag "href" */
           4    private final String HREF_REGEX = "href=\".*?\"";
           5    /** The pattern for linke with the tag "a" */
           6    private final Pattern A_PATTERN = Pattern.compile(A_REGEX);
           7    /** The pattern for url with the tag "href" */
           8    private final Pattern HREF_PATTERN = Pattern.compile(HREF_REGEX);
           9    /**
          10     * Get url address from the url and the content of the url
          11     * @param url the url need to be get links
          12     * @param content the content of the given url
          13     * @return a list with the url address of the links
          14     */

          15    public List<String> getLinkList( URL url, String content )
          16    {
          17        List<String> linkList = new LinkedList<String>();
          18        final Matcher a_matcher = A_PATTERN.matcher(content);
          19        while (a_matcher.find()) 
          20        {
          21            //JUST FOR TEST!
          22//            System.out.println(a_matcher.group());
          23            //get url address
          24            final Matcher myurl = HREF_PATTERN.matcher(a_matcher.group());
          25            while (myurl.find())
          26            {
          27                String urlAddress = myurl.group().replaceAll("href=|>|\"|\"""");
          28                if( urlAddress.startsWith("http") )
          29                {
          30                    linkList.add(urlAddress);
          31                }

          32                else if( urlAddress.startsWith("/"|| urlAddress.startsWith("\\") )
          33                {
          34                    linkList.add(url.getPath()+urlAddress);
          35                }

          36                else
          37                {
          38                    String fullUrl = url.toString();
          39                    //the length of the url without the current page
          40                    int lastSlash = fullUrl.lastIndexOf("/"+ 1;
          41                    linkList.add(fullUrl.substring(0,lastSlash) + urlAddress);
          42                }

          43            }

          44        }

          45        return linkList;
          46    }

          posted @ 2009-11-05 03:00 甜菜侯爵 閱讀(456) | 評論 (0)編輯 收藏

          2009年10月28日

          彩票選號后的數學——抽牌算法的實現

          中國的彩票選號,例如36選7,從36個數字中隨機選取7個,這在算法上如何實現呢?

          最簡單的想法就是,每次都從1~36隨機選取一個數,一共選7次,不就可以了嗎?
          但這樣會有一個問題——重復。彩票選號是不能重復的,這也即是說如果你第一次選到的數是10,那么以后再從1~36中選數的時候,10就不能再選了。
          有人可能會說了,這還不好辦,如果重復了就廢掉,重新再選一個唄。
          這的確是一種解決方法,但是會有很大的問題,比如說5選4吧,前三個都已經選好了是2,3,4,現在取第4個數,這種情況下,取到1和5的幾率要比取到2,3,4的幾率還要小,也就是說,最壞的情況下,有可能會取很多次2,3,4,扔掉很多次,才最終能取到1或5,完成4個隨機數字的選擇。顯然,這樣效率是有很大問題的。

          下面就介紹一種算法:抽牌算法,來實現這種不允許重復的選號,同時不會出現這種效率上的問題。
          [separator]
          抽牌算法的核心思想如下:
          以36選7為例
          一副牌,一共36張,抽出其中一張牌,放到一邊,再從剩下的牌中抽出第二張,放到一邊……以此類推,直到抽完了7張牌為止。
          很顯然,這樣抽牌是絕對不會重復的。而其核心就是抽出的牌要放到一邊

          用算法如何實現呢?
          其實很簡單,只要能模擬實現把抽出的牌放到一邊這個概念就可以了,而模擬實現的方法是非常簡單的:把一個數組模擬成一個牌盒,用數組里存的數模擬牌,而抽出的牌放到一邊的動作,只需進行一次數組交換,把它放到數組的末尾即可。

          以36選7為例
          初始化數組,其結構為[1,2.....35,36]
          第一輪,從1~36序號中選取隨機序號,抽取到序號7, 把序號7和序號36的值交換,7放到數組的末尾,數組結構變成[1...6,36,8......34,35,7]
          第二輪,從1~35序號中選取隨機序號,抽取到7(這時位置7所存的數就是36了),把36和35交換,數組結構就變成了[1..6,35,8...34,36,7]
          第三輪,從1~34序號中選取隨機序號,抽取到5,把5和34交換,數組結構變成了[1...4,34,6,35,8....5,36,7]
          ...
          每一次,都把抽出的“牌”放到數組的最后,然后再抽牌時,就不抽最后那張牌,這樣就實現了抽出的牌放到一邊這樣一個概念。

          請看以下Java代碼:
          Java code
          //獲得不重復的隨機數數組,取值范圍[min,max),個數size public static int[] getRandomIntWithoutReduplicate( int min, int max, int size ) { int[] result = new int[size];//用于存儲結果的數組 int arraySize = max - min;//用于放"牌"的數組大小 int[] intArray = new int[arraySize];//用于放"牌"的數組 // 初始化"牌盒",比如取值范圍是[3,10)則"牌盒"里放的"牌"就是3,4,5,6,7,8,9 for( int i = 0 ; i < intArray.length ; i++ ) { intArray[i] = i + min; } // 獲取不重復的隨機數數組 for( int i = 0 ; i < size ; i++ ) { int c = getRandomInt( min, max - i );//獲取到一個隨機數 int index = c - min;//這個隨機數在"牌盒"里的位置 swap( intArray, index, arraySize - 1 - i );//將這張"牌"放到"牌盒"的最后面 result[i] = intArray[ arraySize - 1 - i ];//把這張"牌"的值扔到存儲結果的數組里 } return result; } //獲取隨機數,隨機數取值范圍為[min, max) public static int getRandomInt( int min, int max ) { // include min, exclude max int result = min + new Double( Math.random() * ( max - min ) ).intValue(); return result; } private static void swap( int[] array, int x, int y ) {//交換數組arry, 序號x與序號y值的順序 int temp = array[x]; array[x] = array[y]; array[y] = temp; }

          posted @ 2009-10-27 21:25 甜菜侯爵 閱讀(338) | 評論 (0)編輯 收藏

          僅列出標題  
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 内黄县| 株洲县| 蒙自县| 彭泽县| 息烽县| 呼伦贝尔市| 长海县| 建平县| 沙洋县| 班戈县| 广宗县| 定南县| 老河口市| 陆良县| 渭源县| 凤翔县| 青铜峡市| 南通市| 尚志市| 广西| 天镇县| 承德市| 肥乡县| 双峰县| 丰城市| 双辽市| 阿勒泰市| 鹤峰县| 恭城| 丽水市| 习水县| 抚远县| 南投县| 都江堰市| 调兵山市| 屏山县| 贺兰县| 抚松县| 尤溪县| 台山市| 沅江市|