import math
import time
import random
import string
from scipy.stats import t
#喊七,按照题目要求,实质就是对输入数据进行排序即可,由大到小、
#喊七,逢七过,未知人数,未知什么时候结尾,在只知道每个人喊了多少次过的情况下,需要根据每个人喊过的次数来重新排列出他们分别是在几号位,即第几个开始喊的
def seven_counts(player_num,ed_num):
temp_list = ['过' if i % 7 == 0 or '7' in str(i) else i for i in range(1,ed_num)]
temp_dict = {}
all_value = []
for i in range(math.ceil(len(temp_list)/player_num)):
all_value.append(temp_list[player_num*i:(i+1)*player_num])
for i in range(len(all_value)):
for j in range(len(all_value[i])):
if all_value[i][j] == '过' and j not in temp_dict.keys():
temp_dict[j] = 1
elif all_value[i][j] == '过':
temp_dict[j] += 1
else:
pass
return temp_dict
def seven_function():
input_value = input('please input the num:\t')
origin_list = input_value.split(' ')
player_num = len(origin_list)
counts = sum([int(i) for i in origin_list])
s = 1
while True:
result = seven_counts(player_num,s)
s += 1
if sum(list(result.values())) == counts:
for i in range(len(result.keys())):
print(result[i],end=' ')
break
#最长子字符串长度,首尾相连成环形、
#统计以o结尾且为偶数位的长度,如果字符串中含o的个数为奇数,则取到前一个即可
def length_str(strs):
temp_list = []
for i in range(len(strs)):
if strs[i] == 'o':
temp_list.append(i)
if len(temp_list) % 2 == 0:
print(temp_list[len(temp_list)-1] + 1)
# print(max(len(temp_list)))
else:
print(temp_list[len(temp_list) - 2] + 1)
# 字符串统计及排序
#统计一个字符串中每个字母出现的次数并排序,按照字母自然顺序排列
def sort_str(strs):
temp_dict = {}
for word in strs:
if word not in temp_dict.keys():
temp_dict[word] = 1
else:
temp_dict[word] += 1
for keys_word in string.ascii_letters:
for j in temp_dict.keys():
if j == keys_word:
print('%s:%s'%(j,temp_dict[j]),end=';')
#字符串反转
#将每个字符串做为一个基本元素对象进行翻转
def reverse_words(strs):
args_word = strs.split('\n')
st_num = int(args_word[1])
ed_num = int(args_word[2])
words = args_word[0].split(' ')
words[st_num:ed_num+1] = words[st_num:ed_num+1][::-1]
print(' '.join(words))
说明:如果有人看了这个文档之后,题目建议自己去找一下,我这边只是为了方便自己看一下逻辑,所以题目没有写的很清楚,只写了一些关键字。