题1:https://www.lanqiao.cn/problems/504/learning/
没有考虑单词相等的情况:(x)
import os import sys inputWord = input() maxLetter = 0 for letter in inputWord: count = inputWord.count(letter) if(count > maxLetter): maxLetter = count theLetter = letter print(theLetter) print(maxLetter)
更改:
import os import sys inputWord = input() maxLetter = 0 Letter = [] for letter in inputWord: count = inputWord.count(letter) if(count >= maxLetter): maxLetter = count for j in inputWord: if inputWord.count(j)==maxLetter: Letter.append(j) Letter.sort() print(Letter[0]) print(maxLetter)
题2:https://www.lanqiao.cn/problems/502/learning/
一次过
import os import sys numberOfPeople = eval(input()) score = [] failPeople = 0 goodPeople = 0 passRate = 0 goodRate = 0 for i in range(numberOfPeople): scoreInput = input() score.append(scoreInput) for marks in score: marks = int(marks) if (marks<60): failPeople += 1 if (marks>=85): goodPeople += 1 passRate = round((1-failPeople/numberOfPeople)*100) goodRate = round((goodPeople/numberOfPeople)*100) print("{}%".format(passRate)) print("{}%".format(goodRate))
一眼看出6,这题不算。
题3:https://www.lanqiao.cn/problems/592/learning/
join函数有点忘了,看了答案,思路一样
import os import sys print("".join([str(i) for i in range(1, 2021)]).count("2"))
题4:https://www.lanqiao.cn/problems/1443/learning/
第一次失败:时间问题
import os import sys theNumbersNeed = [] theMaxNumber = 0 flag = 0 for i in range(1,4000): theNumbersNeed="".join([str(i) for i in range(1, i)]) if(theNumbersNeed.count(str(1))==2021): flag += 1 if(flag == 1): print(i) break
第二次发现上一种方法绕弯了,毕竟join函数遍历这么多次
import os import sys sum = 0 for i in range(1,4000): sum += str(i).count("1") if(sum==2021): print(i) break
题5:https://www.lanqiao.cn/problems/645/learning/
学到了如何使用data打包数据,尔后就像计算机二级里面对文件处理一样。
第一次是抄的:
import os import sys import math data = ''' **** 180.90 88折 **** 10.25 65折 **** 56.14 9折 **** 104.65 9折 **** 100.30 88折 **** 297.15 半价 **** 26.75 65折 **** 130.62 半价 **** 240.28 58折 **** 270.62 8折 **** 115.87 88折 **** 247.34 95折 **** 73.21 9折 **** 101.00 半价 **** 79.54 半价 **** 278.44 7折 **** 199.26 半价 **** 12.97 9折 **** 166.30 78折 **** 125.50 58折 **** 84.98 9折 **** 113.35 68折 **** 166.57 半价 **** 42.56 9折 **** 81.90 95折 **** 131.78 8折 **** 255.89 78折 **** 109.17 9折 **** 146.69 68折 **** 139.33 65折 **** 141.16 78折 **** 154.74 8折 **** 59.42 8折 **** 85.44 68折 **** 293.70 88折 **** 261.79 65折 **** 11.30 88折 **** 268.27 58折 **** 128.29 88折 **** 251.03 8折 **** 208.39 75折 **** 128.88 75折 **** 62.06 9折 **** 225.87 75折 **** 12.89 75折 **** 34.28 75折 **** 62.16 58折 **** 129.12 半价 **** 218.37 半价 **** 289.69 8折 ''' data = data.split() sum = 0 for i in range(0,len(data),3): price = float(data[i+1]) discount = data[i+2] if len(discount) == 2: if discount == "半价": discount = 0.5 else: discount = float(discount[:-1])*0.1 else: discount = float(discount[:-1])*0.01 sum += price*discount print(math.ceil(sum/100)*100)
自己更改了之后:巨慢,因为之前是挑选出len为2的再判断是不是半价,我是直接判断半价所以会比较慢。
import os import sys import math data = ''' **** 180.90 88折 **** 10.25 65折 **** 56.14 9折 **** 104.65 9折 **** 100.30 88折 **** 297.15 半价 **** 26.75 65折 **** 130.62 半价 **** 240.28 58折 **** 270.62 8折 **** 115.87 88折 **** 247.34 95折 **** 73.21 9折 **** 101.00 半价 **** 79.54 半价 **** 278.44 7折 **** 199.26 半价 **** 12.97 9折 **** 166.30 78折 **** 125.50 58折 **** 84.98 9折 **** 113.35 68折 **** 166.57 半价 **** 42.56 9折 **** 81.90 95折 **** 131.78 8折 **** 255.89 78折 **** 109.17 9折 **** 146.69 68折 **** 139.33 65折 **** 141.16 78折 **** 154.74 8折 **** 59.42 8折 **** 85.44 68折 **** 293.70 88折 **** 261.79 65折 **** 11.30 88折 **** 268.27 58折 **** 128.29 88折 **** 251.03 8折 **** 208.39 75折 **** 128.88 75折 **** 62.06 9折 **** 225.87 75折 **** 12.89 75折 **** 34.28 75折 **** 62.16 58折 **** 129.12 半价 **** 218.37 半价 **** 289.69 8折 ''' data = data.split() sum =0 for i in range(0,len(data),3): eachPrice = float(data[i+1]) discount = 0 if(data[i+2] == "半价"): discount = 0.5 elif(len(data[i+2])==3): discount = float(data[i+2][:-1])*0.01 else: discount = float(data[i+2][:-1])*0.1 sum += eachPrice*discount print(math.ceil(sum/100)*100)
标签:count,20,半价,discount,88,2022,import,data From: https://www.cnblogs.com/MrMKG/p/16608514.html