
CheckIO_OJ
CheckIO_OJ 部分题目解决
小白笑苍
沉默是一种生活方式。
展开
-
Monkey Typing
题目Monkey Typing一些思路本质上是一个判断字符串是否包含子字符串的问题,可以用str.find(),str.index(), xx in xxx 等方法我的代码def count_words(text: str, words: set) -> int: #依次判断words里面的word是否在text出现 count = 0 ...原创 2018-05-02 17:44:15 · 1778 阅读 · 0 评论 -
Sun Angle
题目Sun Angle我的代码思路忽略硬编码,正则取小时,分钟,判断范围,求角度import redef sun_angle(time): reg = re.compile('(?P<hour>\d+):(?P<minute>\d+)') regMatch = reg.match(time) timeDict = regMa...原创 2018-05-08 16:29:14 · 551 阅读 · 1 评论 -
All the Same
原创 2018-05-08 15:33:51 · 374 阅读 · 0 评论 -
First Word
题目 提取字符串的第一个单词,不包括空格和标点符号思路re.sub()将标点符号替换成空格,再用split()分离我的代码import redef first_word(text: str) -> str: filter_string = re.sub('[\s+\.\!\/_,$%^*(+\")]+|[+——()?【】“”!,。?、~@#¥%……&am...原创 2018-05-10 17:25:17 · 872 阅读 · 0 评论 -
Correct Sentence
题目Correct Sentence 首字母大写,最后字符不是句号则添加句号我的代码def correct_sentence(text: str) -> str: if len(text) == 0: return text text_list = list(text) if text_list[-1] != '.': ...原创 2018-05-10 17:02:45 · 486 阅读 · 0 评论 -
All the Same
题目All the Same思路比较简单,判断list长度和第一个元素的个数是否一致就行我的代码from typing import List, Anydef all_the_same(elements: List[Any]) -> bool: # your code here if len(elements) == 0: ret...原创 2018-05-03 17:28:42 · 680 阅读 · 0 评论 -
Long Repeat
题目Long Repeat思路遍历用几个标志位记录下当前最长长度,前一个字符,当前长度信息,更新即可我的代码def long_repeat(line): max_length = 0 previous_char = '' length = 0 for letter in line: if letter != previou...原创 2018-05-03 17:23:51 · 330 阅读 · 0 评论 -
The Most Wanted Letter
题目The Most Wanted Letter思路不需要提前用lower方法来全部小写化,在大数据量时比较慢,直接遍历一次分别判断统计就行。统计count存在长度为26的list中,下标表示偏移量,最后遍历count list来求最高频的字母其实像具体字符的ASCII固定的order(),len()固定的可以硬编码写死,效率高很多,不用每次循环都去调,但是编码规范,可读性这些...原创 2018-05-03 14:17:38 · 231 阅读 · 0 评论 -
Non-unique Elements
题目Non-unique Elements思路dict存每个数字出现的次数,出现一次的remove掉我的代码#Your optional code here#You can import some modules or create additional functionsdef checkio(data: list) -> list: #遍历一遍...原创 2018-05-03 16:18:56 · 2358 阅读 · 0 评论 -
Xs and Os Referee
题目Xs and Os Referee思路横竖6种,斜着两种,分别判断是否一致,一致且不为空则返回其值,都不满足则返回平局我的代码def checkio(game_result: list) -> str: result = 'D' #斜着2种 if game_result[0][0] == game_result[1][1] == game_...原创 2018-05-03 09:41:51 · 276 阅读 · 0 评论 -
Say Hi
题目Say Hi我的代码def say_hi(name: str, age: int) -> str: # your code here return "Hi. My name is {name} and I'm {age} years old".format(name = name,age = age)if __name__ == '__main__'...原创 2018-05-08 16:34:26 · 438 阅读 · 0 评论