2009年10月28日

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

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

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

          世界十大最糟糕網頁設計

          鏈接如下:

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

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

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

          這個就比較簡單了,正則式是 “<[^>]*>”,其表意為“以<開頭的,后續(xù)任意個不為>的字符,并以>結尾的字符串”
          這樣做的目的是為了獲得所謂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)編輯 收藏

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

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

          代碼如下:

           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)編輯 收藏

          彩票選號后的數(shù)學——抽牌算法的實現(xiàn)

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

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

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

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

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

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

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

          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          導航

          統(tǒng)計

          常用鏈接

          留言簿

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 巴中市| 瑞金市| 富蕴县| 高要市| 武山县| 隆安县| 鄂托克旗| 夏河县| 吉林市| 宾阳县| 兰州市| 平顺县| 大宁县| 鹤壁市| 昌乐县| 信阳市| 昆山市| 东海县| 康保县| 木里| 织金县| 大悟县| 乐安县| 冀州市| 措美县| 武穴市| 隆林| 江永县| 淄博市| 盐津县| 吉林省| 华宁县| 昔阳县| 安龙县| 高尔夫| 太湖县| 那坡县| 绥江县| 石河子市| 广平县| 嘉荫县|