-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths.py
43 lines (38 loc) · 895 Bytes
/
s.py
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
# -*- coding:utf-8 -*-
#将字符串中的空格替换成%20
def replaceSpace(s):
# write code here
l = len(s)
print 'l:',l
num_blank=0
for i in s:
if i==' ':
num_blank+=1
l_new = l+num_blank*2
print 'l_new:',l_new
index_old = l-1
index_new = l_new
s_new=[' ']*l_new
while(index_old >= 0 and index_new > index_old):
if s[index_old]==' ':
#index_new-=1
s_new[index_new-1]='0'
#index_new-=1
s_new[index_new-2]='2'
#index_new-=1
s_new[index_new-3]='%'
index_new-=3
else:
print index_new
s_new[index_new-1]=s[index_old]
index_new-=1
index_old-=1
ss=''
print s_new
for i in s_new:
ss+=str(i)
return ss
s='We are happy.'
print "s:",s
s1=replaceSpace(s)
print "s1:",s1