From 2f674dc80f0382f1c3178f435714960734dc9d3c Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sat, 6 Jun 2020 21:33:13 +0700 Subject: Reorganize stuff from secondary school --- tht/C/Q-2016/bai2.inp | 1 - tht/C/Q-2016/bai2.out | 4 ---- tht/C/Q-2016/bai2.py | 47 ----------------------------------------------- tht/C/Q-2016/bai3.py | 14 -------------- 4 files changed, 66 deletions(-) delete mode 100644 tht/C/Q-2016/bai2.inp delete mode 100644 tht/C/Q-2016/bai2.out delete mode 100644 tht/C/Q-2016/bai2.py delete mode 100644 tht/C/Q-2016/bai3.py (limited to 'tht/C/Q-2016') diff --git a/tht/C/Q-2016/bai2.inp b/tht/C/Q-2016/bai2.inp deleted file mode 100644 index 9a73285..0000000 --- a/tht/C/Q-2016/bai2.inp +++ /dev/null @@ -1 +0,0 @@ -1-2.(3-4.5) diff --git a/tht/C/Q-2016/bai2.out b/tht/C/Q-2016/bai2.out deleted file mode 100644 index b0a3d7f..0000000 --- a/tht/C/Q-2016/bai2.out +++ /dev/null @@ -1,4 +0,0 @@ -1-2.(3-4.5) -=1-2.(3-4.5) -=1-2.(3-20) -=1-2.-17 diff --git a/tht/C/Q-2016/bai2.py b/tht/C/Q-2016/bai2.py deleted file mode 100644 index bb04c54..0000000 --- a/tht/C/Q-2016/bai2.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -d = {'+': '+', '-': '-', '.': '*', ':': '/', '^': '**'} - -def Steps(string): - val = int() - for char in string: - if char in '+-.:^': - val += 1 - return val - -def Calc(string): - global d - for char in '+-.:^': - string = string.replace(char, ' {} '.format(char)) - l = string.split() - for char in '^.:+-': - if char in l: - idx = l.index(char) - s = ' '.join(l[idx - 1:idx + 2]) - return string.replace(s, str(eval(s.replace(char, d[char])))) - -def MetaCalc(string): - for idx0, char0 in enumerate(string): - if char0 == ')': - for idx1, char1 in enumerate(reversed(string)): - if char1 == '(': - idx1 = len(string) - idx1 - 1 - s = '({})'.format(Calc(string[idx1 + 1:idx0])) - if not(Steps(s)) or ((Steps(s) == 1) and (s[:2] == '(-')): - s = s[1:-1] - return string.replace(string[idx1:idx0 + 1], s) - return Calc(string) - -with open('bai2.inp') as f: - s = f.readline() -lines = Steps(s) -for i in d: - s = s.replace(i, ' ' + i + ' ') -for i in d: - s = s.replace(i + ' - ', i + ' -') -l = s.split() -with open('bai2.out', 'w') as f: - f.write(''.join(l) + '\n') - for _ in range(lines): - s = MetaCalc(s).replace(' ', '') - f.write('=' + s) - print(s) diff --git a/tht/C/Q-2016/bai3.py b/tht/C/Q-2016/bai3.py deleted file mode 100644 index f4139a9..0000000 --- a/tht/C/Q-2016/bai3.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python3 -d = dict() -with open('bai3.inp') as f: - for i in f.readlines(): - for j in '.,;!?': - i = i.replace(j, ' ') - for j in i.split(): - d[j] = d.get(j, 0) + 1 -l = [(value, key) for (key, value) in d.items()] -l.sort(reverse=True) -with open('bai3.out', 'w') as f: - f.write(str(len(l)) + '\n') - for i, j in l: - f.write('{} {}\n'.format(i, j)) -- cgit 1.4.1