
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 · 1872 阅读 · 0 评论 -
Sun Angle
题目 Sun Angle 我的代码 思路 忽略硬编码,正则取小时,分钟,判断范围,求角度 import re def sun_angle(time): reg = re.compile('(?P<hour>\d+):(?P<minute>\d+)') regMatch = reg.match(time) timeDict = regMa...原创 2018-05-08 16:29:14 · 563 阅读 · 1 评论 -
All the Same
原创 2018-05-08 15:33:51 · 390 阅读 · 0 评论 -
First Word
题目 提取字符串的第一个单词,不包括空格和标点符号 思路 re.sub()将标点符号替换成空格,再用split()分离 我的代码 import re def first_word(text: str) -> str: filter_string = re.sub('[\s+\.\!\/_,$%^*(+\")]+|[+——()?【】“”!,。?、~@#¥%……&am...原创 2018-05-10 17:25:17 · 897 阅读 · 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 · 517 阅读 · 0 评论 -
All the Same
题目 All the Same 思路 比较简单,判断list长度和第一个元素的个数是否一致就行 我的代码 from typing import List, Any def all_the_same(elements: List[Any]) -> bool: # your code here if len(elements) == 0: ret...原创 2018-05-03 17:28:42 · 696 阅读 · 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 · 343 阅读 · 0 评论 -
The Most Wanted Letter
题目 The Most Wanted Letter 思路 不需要提前用lower方法来全部小写化,在大数据量时比较慢,直接遍历一次分别判断统计就行。统计count存在长度为26的list中,下标表示偏移量,最后遍历count list来求最高频的字母 其实像具体字符的ASCII固定的order(),len()固定的可以硬编码写死,效率高很多,不用每次循环都去调,但是编码规范,可读性这些...原创 2018-05-03 14:17:38 · 246 阅读 · 0 评论 -
Non-unique Elements
题目 Non-unique Elements 思路 dict存每个数字出现的次数,出现一次的remove掉 我的代码 #Your optional code here #You can import some modules or create additional functions def checkio(data: list) -> list: #遍历一遍...原创 2018-05-03 16:18:56 · 2373 阅读 · 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 · 290 阅读 · 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 · 454 阅读 · 0 评论