2019/10/12
#wrong
time = input().split(" ")
hours = int(time[2])-int(time[0])
minutes = 60-int(time[1]) + int(time[3])
print(str(hours-1)+" "+str(minutes))
- 统一单位之后一切都好办
#right
time = "12 50 19 10".split(" ")
first = 60*int(time[0]) + int(time[1])
second = 60*int(time[2]) + int(time[3])
minus = second - first
#
print(str(minus//60),str(minus%60))
#
2019/12/13
- 计算0的个数可以换成计算2和5的个数,进而转化成算5的个数
def trailingZeros(self,n):
# write your code here, try to do it without arithmetic operators.
num = 0
while n>0:
num = num + n//5
n = n//5
return num
2019/12/14
- 将数字转化成字符串进行处理
def digitCounts(self, k, n):
# write your code here
#
str_k = str(k)
#
count = 0
for i in range(n+1):
for j in str(i):
if j == str_k:
count = count+1
return count
2019/12/15
n = int(input())
times = 0
#
if n == 1:
print(0)
#
else:
while n != 1:
if n%2 == 0:
n = n/2
times +=1
else:
n = (3*n+1)/2
times +=1
print(times)
- 数字转化成字符串处理
num = input()
sum = 0
d = {"1":"yi","2":"er","3":"san","4":"si","5":"wu","6":"liu","7":"qi","8":"ba","9":"jiu","0":"ling"}
for i in num:
sum += int(i)
str_sum = str(sum)
iteration_times = len(str_sum)-1
#格式化输出
for j in range(iteration_times): #int不能迭代。。变量名iteration自然而然以为是迭代了
print(d[str_sum[j]],end=" ")
print(d[str_sum[-1]],end="")
#
#现在看看自己三个星期前写的真的很搞笑
num = input()
sum = 0
d = {1:"yi",2:"er",3:"san",4:"si",5:"wu",6:"liu",7:"qi",8:"ba",9:"jiu",0:"ling"}
for i in num:
number = number + int(i)
if number//100 != 0 :
hundred = number//100
else:
hundred = 0
if (number-hundred*100)//10 != 0 :
decade = (number-hundred*100)//10
else:
decade = 0
if (number-hundred*100-decade*10) != 0 :
digit = number-hundred*100-decade*10
else:
digit = 0
if hundred:
print(d[hundred],end=" ")
if decade:
print(d[decade],end=" ")
if digit:
print(d[digit])
else:
print(d[0])
来源:CSDN
作者:头 号 玩 家
链接:https://blog.csdn.net/qq_44353473/article/details/103542960