Skip to content

Commit eb2101a

Browse files
committed
add
1 parent def94ff commit eb2101a

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

Forec/0006/0006.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# coding = utf-8
2+
__author__ = 'Forec'
3+
import os, re
4+
5+
def find_word(file_path):
6+
file_list = os.listdir(file_path)
7+
word_dic = {}
8+
word_re = re.compile(r'[\w]+')
9+
for x in file_list:
10+
if os.path.isfile(x) and os.path.splitext(x)[1] =='.txt' :
11+
try:
12+
f = open(x, 'r')
13+
data = f.read()
14+
f.close()
15+
words = word_re.findall(data)
16+
for word in words:
17+
if word not in word_dic:
18+
word_dic[word] = 1
19+
else:
20+
word_dic[word] += 1
21+
except:
22+
print('Open %s Error' % x)
23+
Ans_List = sorted(word_dic.items(), key = lambda t : t[1], reverse = True)
24+
for key, value in Ans_List:
25+
print( 'Word ', key, 'appears %d times' % value )
26+
27+
find_word('.')

Forec/0007/0007.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# coding = utf-8
2+
# Can detect .py / .c / .cpp
3+
__author__ = 'Forec'
4+
import os
5+
import re
6+
7+
def get_line( file_path ):
8+
file_dir = os.listdir(file_path)
9+
code ,exp ,space ,alls = ( 0, 0 ,0 , 0)
10+
cFlag = True
11+
exp_re = re.compile(r'[\"\'].*?[\"\']')
12+
for x in file_dir:
13+
if os.path.isfile(x) and (
14+
os.path.splitext(x)[1] == '.py'
15+
or os.path.splitext(x)[1] == '.c'
16+
or os.path.splitext(x)[1] == '.cpp'
17+
):
18+
try:
19+
f = open( x, 'r' )
20+
except:
21+
print('Cannot open file %s' % x)
22+
for line in f.readlines():
23+
alls += 1
24+
if line.strip() == '' and cFlag:
25+
space += 1
26+
continue
27+
find_exp = exp_re.findall(line)
28+
for strs in find_exp:
29+
line = line.replace(strs,'')
30+
if os.path.splitext(x)[1] == '.py':
31+
if '#' in line:
32+
exp += 1
33+
else :
34+
code += 1
35+
elif os.path.splitext(x)[1] == '.c' or os.path.splitext(x)[1] == '.cpp':
36+
if r'*/' in line:
37+
cFlag = True
38+
exp += 1
39+
elif r'/*' in line:
40+
cFlag = False
41+
exp += 1
42+
elif not cFlag:
43+
exp += 1
44+
elif r'//' in line:
45+
exp += 1
46+
else:
47+
code += 1
48+
cFlag = True
49+
try:
50+
f.close()
51+
except:
52+
pass
53+
54+
print( '''All Lines total : %d
55+
Codes total : %d
56+
Spaces total: %d
57+
Explanation : %d'''
58+
% ( alls, code, space, exp ))
59+
60+
get_line('.')

Forec/0009/0009.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#coding = utf-8
2+
__author__ = 'Forec'
3+
4+
import requests
5+
import re
6+
from bs4 import BeautifulSoup
7+
8+
url = input()
9+
html = requests.get(url)
10+
11+
soup = BeautifulSoup(html.text,"html.parser")
12+
find_href = soup.findAll('a')
13+
for x in find_href:
14+
print(x['href'])

0 commit comments

Comments
 (0)