• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            coreBugZJ

            此 blog 已棄。

            PALIN - SPOJ 5. The Next Palindrome

            A positive integer is called a palindrome if its representation in the decimal system is the same when read from left to right and from right to left. For a given positive integer K of not more than 1000000 digits, write the value of the smallest palindrome larger than K to output. Numbers are always displayed without leading zeros.

            Input

            The first line contains integer t, the number of test cases. Integers K are given in the next t lines.

            Output

            For each K, output the smallest palindrome larger than K.

            Example

            Input:
            2
            808
            2133

            Output:
            818
            2222

            Warning: large Input/Output data, be careful with certain languages


            問題:
            求出比輸入整數大的最小的回文數,輸入整數不超過 1000000 個數字。

            解法:
            貪心。

            代碼 LISP SBCL :
             1(defun digit-succ(x)
             2 (elt "0123456789A" (position x "*0123456789")))
             3
             4(let ((num (read)))
             5 (dotimes (ca num)
             6  (let* ((str (read-line))
             7         (len (length str))
             8         (cmp 0)
             9         (i nil)
            10         (j nil))
            11   (dotimes (i (floor (/ (1+ len) 2)))
            12    (setf j (1- (- len i)))
            13    (when (char> (elt str i) (elt str j))
            14     (setf cmp 1))
            15    (when (char< (elt str i) (elt str j))
            16     (setf cmp -1))
            17    (setf (elt str j) (elt str i)))
            18   (when (<= cmp 0)
            19    (setf i (1- (floor (/ (1+ len) 2))))
            20    (setf j (if (oddp len) i (1+ i)))
            21    (do ()
            22     ((or (minusp i) (char< (elt str i) #\9)))
            23     (setf (elt str i) #\0)
            24     (setf (elt str j) #\0)
            25     (decf i)
            26     (incf j))
            27    (when (minusp i)
            28     (setf (elt str 0) #\1)
            29     (write-string str)
            30     (write-char #\1))
            31    (when (not (minusp i))
            32     (setf (elt str i) (digit-succ (elt str i)))
            33     (setf (elt str j) (elt str i))
            34     (write-string str)))
            35   (when (plusp cmp)
            36    (write-string str))
            37   (fresh-line))))
            38
            39


            posted on 2012-02-19 16:18 coreBugZJ 閱讀(416) 評論(0)  編輯 收藏 引用 所屬分類: ACMAlgorithmLisp

            久久久久久综合一区中文字幕| 人人狠狠综合88综合久久| 亚洲国产精品无码久久SM| 日韩精品久久无码人妻中文字幕 | 99久久精品国产一区二区| 久久婷婷人人澡人人| 日韩精品久久久久久久电影蜜臀| 久久精品9988| 亚洲欧洲中文日韩久久AV乱码| 久久亚洲综合色一区二区三区| 久久亚洲欧美国产精品| 久久久久亚洲AV无码去区首| 久久丫精品国产亚洲av不卡| 久久综合精品国产一区二区三区| 久久午夜无码鲁丝片| 亚洲欧美一区二区三区久久| 精品久久久久久国产91| 久久久久亚洲AV无码专区首JN| 亚洲国产精品久久久久| 久久国产精品99国产精| 偷偷做久久久久网站| 久久综合伊人77777| 久久国产香蕉一区精品| 久久精品国产亚洲一区二区| 久久亚洲AV成人出白浆无码国产| 中文字幕亚洲综合久久菠萝蜜| 国产免费福利体检区久久| 久久精品国产精品青草| 久久精品无码午夜福利理论片| 久久丫忘忧草产品| 偷偷做久久久久网站| 思思久久精品在热线热| 久久久久久国产a免费观看黄色大片| 精品久久人人妻人人做精品| 久久综合九色综合97_久久久| 久久久91人妻无码精品蜜桃HD| 无码人妻少妇久久中文字幕| 99热热久久这里只有精品68| 久久国产免费观看精品| 久久精品九九亚洲精品天堂| AV狠狠色丁香婷婷综合久久|