summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-23 10:07:29 +0200
committerGitHub <noreply@github.com>2017-04-23 10:07:29 +0200
commit8317eb9cae7ff46e400534572542496fef508cfc (patch)
treed041703d906544f2bc2208459e0e829bade08b24
parentaf941bef2050f63e110ca30025142b33a6ef7326 (diff)
OII 2017
Scommesse in Python
-rw-r--r--scommesse.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/scommesse.py b/scommesse.py
new file mode 100644
index 0000000..b947df1
--- /dev/null
+++ b/scommesse.py
@@ -0,0 +1,50 @@
+carteV = []
+carteOut = []
+
+
+def cOutPresente(x):
+ s = False
+ for i in range(len(carteOut)):
+ if (carteOut[i] == x):
+ s = True
+
+ if not s:
+ carteOut.append(x)
+
+
+def fCarte(N, start):
+ c = carteV[:]
+
+ while len(c) > 1:
+ tot = len(c)
+ for i in range(start, tot - 1):
+ x = c[i]
+ x1 = c[i + 1]
+ x2 = x + x1
+
+ if ((x2 % 2) != 0):
+ c.remove(x)
+ c.remove(x1)
+ break
+
+ start = 0
+
+ cOutPresente(c[0])
+
+
+with open('input.txt', 'r') as fin:
+ N = int(fin.readline())
+ carteV = fin.readline().split(' ')
+
+for i in range(N):
+ carteV[i] = int(carteV[i])
+
+for i in range(N):
+ fCarte(N, start=i)
+
+with open('output.txt', 'w') as fout:
+ fout.write(str(len(carteOut)))
+ fout.write('\n')
+
+ for i in carteOut:
+ fout.write(str(i) + ' ')