diff --git a/programm13.py b/programm13.py new file mode 100644 index 0000000..3bfd230 --- /dev/null +++ b/programm13.py @@ -0,0 +1,46 @@ +def volodya_add(num1, num2): + """Складывает два числа по алгоритму Володи""" + s1 = str(num1) + s2 = str(num2) + + max_len = max(len(s1), len(s2)) + s1 = s1.zfill(max_len) + s2 = s2.zfill(max_len) + + result = "" + + for i in range(max_len - 1, -1, -1): + digit_sum = int(s1[i]) + int(s2[i]) + result = str(digit_sum) + result + + return int(result) + +with open('INPUT.TXT', 'r') as f: + a, b, c = map(int, f.readline().split()) + +results = set() + +# (a + b) + c +results.add(volodya_add(volodya_add(a, b), c)) +# (a + c) + b +results.add(volodya_add(volodya_add(a, c), b)) +# (b + c) + a +results.add(volodya_add(volodya_add(b, c), a)) + +# a + (b + c) +results.add(volodya_add(a, volodya_add(b, c))) +# b + (a + c) +results.add(volodya_add(b, volodya_add(a, c))) +# c + (a + b) +results.add(volodya_add(c, volodya_add(a, b))) + +sorted_results = sorted(results) + +with open('OUTPUT.TXT', 'w') as f: + if len(results) > 1: + f.write("YES\n") + else: + f.write("NO\n") + + for res in sorted_results: + f.write(str(res) + "\n") \ No newline at end of file