Skip to content

Commit f6287cc

Browse files
committed
0011-0022
1 parent 30c3bef commit f6287cc

27 files changed

+244
-0
lines changed

NKUCodingCat/0011/0011.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os,re
2+
ex = re.split("[\r\n]+",unicode(open(os.path.split(os.path.realpath(__file__))[0]+"/filtered_words.txt").read().decode("GBK")))
3+
while True:
4+
input = raw_input()
5+
if input == "":
6+
break
7+
else:
8+
try:
9+
input = unicode(input)
10+
except:
11+
try:
12+
input = unicode(input.decode("utf-8"))
13+
except:
14+
try:
15+
input = unicode(input.decode("GBK"))
16+
except:
17+
raise "Unknown Codec"
18+
input = re.split("\s+",input)
19+
Flag = True
20+
for i in input:
21+
if i in ex:
22+
print "Human Rights"
23+
Flag = False
24+
break
25+
if Flag:
26+
print "Freedom"
27+

NKUCodingCat/0011/filtered_words.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
����
2+
����Ա
3+
����Ա
4+
�쵼
5+
ţ��
6+
ţ��
7+
����
8+
����
9+
love
10+
sex
11+
jiangge

NKUCodingCat/0012/0012.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os,re
2+
ex = re.split("[\r\n]+",unicode(open(os.path.split(os.path.realpath(__file__))[0]+"/filtered_words.txt").read().decode("GBK")))
3+
Find = re.compile("("+("%s|"*len(ex)%tuple(ex))[:-1]+")")
4+
while True:
5+
input = raw_input()
6+
if input == "":
7+
break
8+
else:
9+
try:
10+
input = unicode(input)
11+
except:
12+
try:
13+
input = unicode(input.decode("utf-8"))
14+
except:
15+
try:
16+
input = unicode(input.decode("GBK"))
17+
except:
18+
raise "Unknown Codec"
19+
print Find.sub("**",input)

NKUCodingCat/0012/filtered_words.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
����
2+
����Ա
3+
����Ա
4+
�쵼
5+
ţ��
6+
ţ��
7+
����
8+
����
9+
love
10+
sex
11+
jiangge

NKUCodingCat/0013/0013.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests,os,re,urllib
2+
from lxml import etree
3+
src = requests.get("""http://tieba.baidu.com/p/2166231880""").content
4+
path = os.path.split(os.path.realpath(__file__))[0]+"/img/"
5+
for i in etree.HTML(src.decode('utf-8', 'ignore')).xpath(u"//img"):
6+
url = i.attrib["src"]
7+
proto, rest = urllib.splittype(url)
8+
host, rest = urllib.splithost(rest)
9+
if host == "imgsrc.baidu.com":
10+
urllib.urlretrieve(url, path+os.path.split(url)[1])

NKUCodingCat/0014/0014.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#coding=utf-8
2+
import json, xlwt, os
3+
f = open(os.path.split(os.path.realpath(__file__))[0]+"/student.txt")
4+
dict = json.loads(f.read().decode("GBK"))
5+
xls = xlwt.Workbook()
6+
sheet = xls.add_sheet("student")
7+
for i in range(len(dict.keys())):
8+
row = i
9+
col = 0
10+
sheet.write(row, col, dict.keys()[i])
11+
for j in (dict[dict.keys()[i]]):
12+
col+=1
13+
sheet.write(row, col, j )
14+
xls.save(os.path.split(os.path.realpath(__file__))[0]+"/student.xls")

NKUCodingCat/0014/student.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"1":["����",150,120,100],
3+
"2":["����",90,99,95],
4+
"3":["����",60,66,68]
5+
}

NKUCodingCat/0014/student.xls

5.5 KB
Binary file not shown.

NKUCodingCat/0015/0015.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#coding=utf-8
2+
import json, xlwt, os
3+
f = open(os.path.split(os.path.realpath(__file__))[0]+"/city.txt")
4+
dict = json.loads(f.read().decode("GBK"))
5+
xls = xlwt.Workbook()
6+
sheet = xls.add_sheet("city")
7+
for i in range(len(dict.keys())):
8+
row = i
9+
col = 0
10+
sheet.write(row, col, dict.keys()[i])
11+
sheet.write(row, col+1, dict[dict.keys()[i]])
12+
xls.save(os.path.split(os.path.realpath(__file__))[0]+"/city.xls")

NKUCodingCat/0015/city.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"1" : "�Ϻ�",
3+
"2" : "����",
4+
"3" : "�ɶ�"
5+
}

NKUCodingCat/0015/city.xls

5.5 KB
Binary file not shown.

NKUCodingCat/0016/0016.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#coding=utf-8
2+
import json, xlwt, os
3+
f = open(os.path.split(os.path.realpath(__file__))[0]+"/numbers.txt")
4+
dict = json.loads(f.read().decode("GBK"))
5+
xls = xlwt.Workbook()
6+
sheet = xls.add_sheet("numbers")
7+
for i in range(len(dict)):
8+
for j in range(len(dict[i])):
9+
sheet.write(i , j, dict[i][j])
10+
xls.save(os.path.split(os.path.realpath(__file__))[0]+"/numbers.xls")

NKUCodingCat/0016/numbers.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
[1, 82, 65535],
3+
[20, 90, 13],
4+
[26, 809, 1024]
5+
]

NKUCodingCat/0016/numbers.xls

5.5 KB
Binary file not shown.

NKUCodingCat/0017/0017.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#coding=utf-8
2+
import xlrd, json, os
3+
from lxml import etree
4+
path = os.path.split(os.path.realpath(__file__))[0]+"/"
5+
data = xlrd.open_workbook(path+"student.xls")
6+
table = data.sheets()[0]
7+
nrows = table.nrows
8+
Dict = {}
9+
for i in range(nrows ):
10+
Arr = table.row_values(i)
11+
Dict[Arr[0]] = Arr[1:]
12+
root = etree.Element("root")
13+
child1 = etree.SubElement(root, "student")
14+
comm = etree.Comment(u"""学生信息表 "id" : [名字, 数学, 语文, 英文]""")
15+
child1.append(comm)
16+
child1.text =unicode(json.dumps(Dict).decode("utf-8"))
17+
tree = etree.ElementTree(root)
18+
tree.write(path+"student.xml ", pretty_print=True, xml_declaration=True, encoding='utf-8')

NKUCodingCat/0017/student.xls

5.5 KB
Binary file not shown.

NKUCodingCat/0017/student.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<root>
3+
<student>{"1": ["\u5f20\u4e09", 150.0, 120.0, 100.0], "3": ["\u738b\u4e94", 60.0, 66.0, 68.0], "2": ["\u674e\u56db", 90.0, 99.0, 95.0]}<!--学生信息表 "id" : [名字, 数学, 语文, 英文]--></student>
4+
</root>

NKUCodingCat/0018/0018.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#coding=utf-8
2+
import xlrd, json, os
3+
from lxml import etree
4+
path = os.path.split(os.path.realpath(__file__))[0]+"/"
5+
data = xlrd.open_workbook(path+"city.xls")
6+
table = data.sheets()[0]
7+
nrows = table.nrows
8+
Dict = {}
9+
for i in range(nrows ):
10+
Arr = table.row_values(i)
11+
Dict[Arr[0]] = Arr[1]
12+
root = etree.Element("root")
13+
child1 = etree.SubElement(root, "city")
14+
comm = etree.Comment(u"""城市信息""")
15+
child1.append(comm)
16+
child1.text =unicode(json.dumps(Dict))
17+
tree = etree.ElementTree(root)
18+
tree.write(path+"city.xml ", pretty_print=True, xml_declaration=True, encoding='utf-8')

NKUCodingCat/0018/city.xls

5.5 KB
Binary file not shown.

NKUCodingCat/0018/city.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<root>
3+
<city>{"1": "\u4e0a\u6d77", "3": "\u6210\u90fd", "2": "\u5317\u4eac"}<!--城市信息--></city>
4+
</root>

NKUCodingCat/0019/0019.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#coding=utf-8
2+
import xlrd, json, os
3+
from lxml import etree
4+
path = os.path.split(os.path.realpath(__file__))[0]+"/"
5+
data = xlrd.open_workbook(path+"numbers.xls")
6+
table = data.sheets()[0]
7+
nrows = table.nrows
8+
Dict = []
9+
for i in range(nrows ):
10+
Arr = table.row_values(i)
11+
Dict.append(Arr)
12+
root = etree.Element("root")
13+
child1 = etree.SubElement(root, "numbers")
14+
comm = etree.Comment(u"""数字信息""")
15+
child1.append(comm)
16+
child1.text =unicode(json.dumps(Dict).decode("utf-8"))
17+
tree = etree.ElementTree(root)
18+
tree.write(path+"numbers.xml ", pretty_print=True, xml_declaration=True, encoding='utf-8')

NKUCodingCat/0019/numbers.xls

5.5 KB
Binary file not shown.

NKUCodingCat/0019/numbers.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<root>
3+
<numbers>[[1.0, 82.0, 65535.0], [20.0, 90.0, 13.0], [26.0, 809.0, 1024.0]]<!--数字信息--></numbers>
4+
</root>

NKUCodingCat/0020/0020.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#coding=utf-8
2+
import xlrd, json, os
3+
from lxml import etree
4+
path = os.path.split(os.path.realpath(__file__))[0]+"/"
5+
data = xlrd.open_workbook(path+"src.xls")
6+
table = data.sheets()[0]
7+
nrows = table.nrows
8+
Sum = 0
9+
for i in range(1,nrows):
10+
Arr = table.row_values(i)
11+
Sum+=int(Arr[3])
12+
print "总计通话时间"+str(Sum)+"秒"

NKUCodingCat/0020/src.xls

43 KB
Binary file not shown.

NKUCodingCat/0021/encry.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#coding=utf-8
2+
import os,time,random,hashlib,math
3+
def md5(str):
4+
m = hashlib.md5()
5+
m.update(str)
6+
return m.hexdigest()
7+
def Salt(len=64):
8+
return "%s"*len%tuple([chr(65+random.randint(0,25)) for i in range(len)])
9+
def encry(Str):
10+
Log = int(math.log(len(Str),2))+1
11+
MaxLen = 2**Log
12+
SAL = Salt(MaxLen-len(Str)+random.randint(8,16))
13+
ENC = md5(Str+SAL)
14+
return SAL,ENC
15+
print encry("sudgds")

NKUCodingCat/0022/0005-yes_I_can.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#coding=utf-8
2+
from __future__ import division
3+
import os
4+
from PIL import Image
5+
def transfer(img_path,dst_width,dst_height,dst_path):
6+
7+
im = Image.open(img_path)
8+
s_w,s_h = im.size
9+
if dst_width/s_w < dst_height/s_h:
10+
ratio = dst_width/s_w
11+
else:
12+
ratio = dst_height/s_h
13+
resized_img = im.resize((int(ratio*s_w), int(ratio*s_h)), Image.ANTIALIAS)
14+
resized_img.save(dst_path)
15+
path = os.path.split(os.path.realpath(__file__))[0]+"/"
16+
src = "img/"
17+
dst = "dst_img/"
18+
imgs = os.listdir(path+src)
19+
for i in imgs:
20+
transfer(path+src+i,1136,640,path+dst+"5-"+i) #iphone5
21+
transfer(path+src+i,1334,750,path+dst+"6-"+i) #iphone6
22+
transfer(path+src+i,2208,1242,path+dst+"6+-"+i) #iphone6+

0 commit comments

Comments
 (0)