-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathJAVAC.py
59 lines (49 loc) · 1.2 KB
/
JAVAC.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
def convert(oStr):
nStr=''
L=len(oStr)
cid=False
jid=False
if not oStr[0].isalpha():
return "Error!"
for i in oStr:
if i.isupper():
jid=True
continue
if i=="_":
cid=True
elif not i.isalpha():
return "Error!"
if cid and jid:
return "Error!"
if cid:
if oStr[0]=='_' or oStr[-1]=='_':
return "Error!"
i=0
while(i<L):
if (oStr[i]=='_' and not oStr[i+1]=='_'):
nStr+=oStr[i+1].upper()
i+=2
elif(oStr[i]=='_' and oStr[i+1]=='_'):
return "Error!"
else:
nStr+=oStr[i]
i+=1
else:
if oStr[0].isupper():
return "Error!"
i=0
while(i<L):
if (oStr[i].isupper()):
nStr+='_'+oStr[i].lower()
else:
nStr+=oStr[i]
i+=1
return nStr
def main():
while True:
try:
oStr=raw_input()
print convert(oStr)
except:
break
main()