-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
94 lines (68 loc) · 1.32 KB
/
Copy pathtest.py
File metadata and controls
94 lines (68 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 1 1 2 3 5 8
firstnumber = 1
secondnumber = 1
print(firstnumber)
print(secondnumber)
count = 0
while count <= 10:
count = count + 1
firstnumber,secondnumber = secondnumber,firstnumber+secondnumber
print(secondnumber)
# swap a b
a = input("请输入a的值:")
b = input("请输入b的值:")
temp = a
a = b
b = temp
print("a的值="+a)
print("b的值="+b)
# Palindrome Number
def isPalindrome(number):
if number < 0:
return False
else:
str1 = str(number)
str2 = str1[::-1]
if str1 == str2:
return True
else:
return False
result = isPalindrome(int(input('请输入一个数字:')))
print(result)
#Roman To Integer
#
def romanToInt(s):
a = {'I':1,
'V':5,
'X':10,
'L':50,
'C':100,
'D':500,
'M':1000}
ans = 0
for i in range(len(s)):
if i ==0 or a[s[i]]<=a[s[i-1]]:
ans+=a[s[i]]
else:
ans+=a[s[i]]-2*a[s[i-1]]
return ans
result = romanToInt(input('请输入罗马字符:'))
print(result)
#Two Sum
def twoSum(nums,target):
for i in range(len(nums)):
x = target - nums[i]
if i in nums and nums.index(x) != i:
return [i,nums.index(x)]
#Reverse Integer
def reverse(x):
max,min = 1<<31,-1<<31
if x < 0 :
str1 = str(-x)
ans = -1*int(str1[::-1])
else:
str2 = str(x)
ans = int(str2[::-1])
if ans < min or ans >= max:
return 0
return ans