Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions JiYouMCC/0007/0007.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import os

CODE_PATH = os.path.join(os.path.dirname(__file__), '..')

code_files = []
code_line_count = 0
code_blank_line_count = 0
code_comment_line_count = 0


def walk(rootDir):
global code_files
for lists in os.listdir(rootDir):
path = os.path.join(rootDir, lists)
if os.path.isdir(path):
walk(path)
else:
if os.path.splitext(lists)[1].upper() == '.PY':
code_files.append(path)

walk(CODE_PATH)
for code_file in code_files:
file = open(code_file)
for line in file:
code_line_count += 1
if line == '\n':
code_blank_line_count += 1
if line.replace(' ', '').replace('\t', '')[0] == '#':
code_comment_line_count += 1
print '文件数量:', len(code_files)
print '代码行数:', code_line_count
print '空行行数:', code_blank_line_count
print '注释行数:', code_comment_line_count
1 change: 1 addition & 0 deletions JiYouMCC/0007/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**第 0007 题:**有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
11 changes: 11 additions & 0 deletions JiYouMCC/0011/0011.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
def word_check(input_word, filtered_words):
for word in filtered_words:
if word in input_word:
return 'Freedom'
return 'Human Rights'

file = open('filtered_words.txt')
filtered_words=[line.replace('\n','') for line in file]
print word_check('程序员在上班。', filtered_words)
print word_check('我妈妈是农民。', filtered_words)
11 changes: 11 additions & 0 deletions JiYouMCC/0011/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge
13 changes: 13 additions & 0 deletions JiYouMCC/0011/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**第 0011 题:** 敏感词文本文件 filtered_words.txt,里面的内容为以下内容,当用户输入敏感词语时,则打印出 Freedom,否则打印出 Human Rights。

北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge
20 changes: 20 additions & 0 deletions JiYouMCC/0012/0012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
import re


def word_change(input_word, filtered_words):
result = input_word
for word in filtered_words:
if word in result:
strinfo = re.compile(word)
result = strinfo.sub('*' * len(word.decode('utf-8')), result)
return result

file = open('filtered_words.txt')
filtered_words = [line.replace('\n', '') for line in file]

print word_change('lovely boy', filtered_words)
print word_change('程序员在上班。', filtered_words)
print word_change('我妈妈是农民。', filtered_words)


11 changes: 11 additions & 0 deletions JiYouMCC/0012/filtered_words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
北京
程序员
公务员
领导
牛比
牛逼
你娘
你妈
love
sex
jiangge
1 change: 1 addition & 0 deletions JiYouMCC/0012/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**第 0012 题:** 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。