summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-30 09:00:48 +0200
committerSanto Cariotti <sancn@live.com>2017-04-30 09:00:48 +0200
commit89a48c17c9a3dadd93e84e891227d1d13558b08e (patch)
tree4de4d5d36672d3f5aecd7d389fd37d55598b90ff
parentb0cda170100021d76056ad09145fc3c3683a354e (diff)
Added parentesi.py
-rw-r--r--python/parentesi.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/python/parentesi.py b/python/parentesi.py
new file mode 100644
index 0000000..a89e046
--- /dev/null
+++ b/python/parentesi.py
@@ -0,0 +1,35 @@
+stringa = []
+
+with open('input.txt', 'r') as fin:
+ linea = fin.readline()
+
+ for i in linea:
+ if i is not ' ':
+ stringa.append(i)
+
+
+t = q = g = 0
+tot = 0
+
+
+for i in range(len(stringa)):
+ if stringa[i] == '(':
+ t += 1
+ elif stringa[i] == '[':
+ q += 1
+ elif stringa[i] == '{':
+ g += 1
+
+ if stringa[i] == ')' and t > 0:
+ t -= 1
+ tot += 1
+ elif stringa[i] == ']' and q > 0:
+ q -= 1
+ tot += 1
+ elif stringa[i] == '}' and g > 0:
+ g -= 1
+ tot += 1
+
+
+with open('output.txt', 'w') as fout:
+ fout.write(str(tot))