Chinaunix首页 | 论坛 | 博客
  • 博客访问: 336059
  • 博文数量: 105
  • 博客积分: 2730
  • 博客等级: 少校
  • 技术积分: 1110
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-20 12:09
文章分类

全部博文(105)

文章存档

2013年(3)

2012年(2)

2011年(36)

2010年(34)

2009年(6)

2008年(20)

2007年(4)

分类:

2010-12-25 15:14:03

这题得一步一步做,所以肯定不断补充的.

0: 2的38次方 这个不说了
1:pc/def/map.html
每个字符+2,当然,yz要绕到ab
------------
import Char
import Data.List
do1 = map inc2 "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. "

inc2 c
  | isLower c && ord c <= ord 'x' = chr (ord c + 2)
  | isLower c && ord c > ord 'x' = chr (ord c - 24)
  | otherwise = c
------------

> do1
结果:
"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why
this text is so long. using string.maketrans() is recommended. now apply on the url. "
意思是用相同的方法搞一下url.实际就是搞"map"三个字
得到答案ocr

2:
找到大串里的字符.
把网页源代码里的那串字贴到文本文件里,2.txt
----------------2.hs
import System.IO
import Char
do2 = do
    content <- readFile "2.txt"
    putStrLn $ filter isAlpha content
----------------
这个很简单,就是用filter函数把符合条件的char过滤出来.
运行do2函数,得到"equality"

3:
找到小写字母,他左边正好3个大写,右边也正好三个大写.(再外面可以是空或者小写)
这里处理边界条件在前后各加一个小写字母即可
------------------3.hs
import System.IO
import Char
import Data.List

data IterSt = IterSt {result :: String, lastSt :: String}

updateState :: IterSt -> Char -> IterSt
updateState (IterSt r st@(a:b:c:d:e:f:g:h:[])) newC =
    if (all isUpper [b,c,d,f,g,h]) && (all isLower [a,e,newC])
    then IterSt (r++[e]) newSt
    else IterSt r newSt
    where newSt = tail st ++ [newC]
updateState (IterSt r a) newC = IterSt r (a++[newC])

filterString :: [Char] -> IterSt
filterString xs = foldl' updateState (IterSt [] []) xs

getString :: IterSt -> String
getString (IterSt str _) = str

do3 = do
    content <- readFile "3.txt"
    putStrLn (getString . filterString $ "a" ++ content ++ "a")
-------------------------
这个要处理一个状态机,要保持上一次的缓冲区以及得到的结果.
update函数每次更新一串当前状态,删除第一个,追加最后一个. 如果匹配模式的话就把结果添加到result列表里.

得到结果linkedlist
linkedlist.html显示linkedlist.php那么就改成php再访问.
阅读(838) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~