diff options
author | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2016-10-31 22:21:50 +0700 |
---|---|---|
committer | Raphael McSinyx <vn.mcsinyx@gmail.com> | 2016-10-31 22:21:50 +0700 |
commit | 71a6e456b59171a681bccff7eeba9db7367bca37 (patch) | |
tree | e6f517c4b4109e13c9bb31df6c4c40185ad7ddf7 /THT/C/Q-2016/bai3.py | |
parent | 250b7d75204bb18311f51d8b67164f9ad4cef9f2 (diff) | |
download | cp-71a6e456b59171a681bccff7eeba9db7367bca37.tar.gz |
Thêm đề Tin học trẻ Quốc gia 2016 Bảng B
Diffstat (limited to 'THT/C/Q-2016/bai3.py')
-rwxr-xr-x | THT/C/Q-2016/bai3.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/THT/C/Q-2016/bai3.py b/THT/C/Q-2016/bai3.py new file mode 100755 index 0000000..f4139a9 --- /dev/null +++ b/THT/C/Q-2016/bai3.py @@ -0,0 +1,14 @@ +#!/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)) |