-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathP12_CompilerVersion.py
43 lines (42 loc) · 1.01 KB
/
P12_CompilerVersion.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
# You are converting an old code for a new version of the compiler.
#
# In the old code we have used "->" for pointers. But now we have to replace each "->" with a ".". But this
# replacement shouldn't be done inside commments. A comment is a string that starts with "//" and terminates
# at the end of the line.
#
# Input:
#
# At max.
# 2000
# 2000 lines of code.
#
# Each line of code consists of at maximum
# 60
# 60 characters.
#
# Output:
#
# New code with required changes.
#
# SAMPLE INPUT
# int t; //variable t
# t->a=0; //t->a does something
# return 0;
#
# SAMPLE OUTPUT
# int t; //variable t
# t.a=0; //t->a does something
# return 0;
import sys
import re
while True:
line = sys.stdin.readline()
if len(line) >=2 :
if '//' in line:
line = re.split("//", line)
line[0] = re.sub("->", ".", line[0])
sys.stdout.write('//'.join(line))
else:
sys.stdout.write(re.sub("->", ".", line))
else:
break