├── ICPC0058 - ĐỈNH THẮT ├── ICPC0101 - THU GỌN DÃY SỐ ├── ICPC0104 - TÌM SỐ NHỎ NHẤT ├── ICPC0105 - TÌM SỐ LỚN NHẤT ├── ICPC0106 - ĐỔI CƠ SỐ - 2 ├── ICPC0107 - THAY ĐỔI CHỮ SỐ ├── ICPC0108 - SUM TRIPLE ZERO ├── ICPC0109 - MIN TRIPLE ├── ICPC0111 - XOAY MẢNG ├── ICPC0112 - PRIME – TRIPLET ├── ICPC0113 - EMIRP NUMBER ├── ICPC0114 - PERFECT PRIME ├── ICPC0115 - SỐ KRISH ├── ICPC0116 - CON SỐ DUYÊN NỢ ├── ICPC0117 - CHÚC MỪNG NĂM MỚI ├── ICPC0118 - CUNG HOÀNG ĐẠO ├── PY00000 - Welcome to python ├── PY01000 - HELLO ├── PY01001 - KIỂM TRA CHẴN LẺ ├── PY01002 - PHÉP CỘNG ├── PY01003 - LÀM TRÒN SỐ ├── PY01004 - NGUYÊN TỐ ├── PY01005 - SỐ MAY MẮN ├── PY01006 - SỐ MAY MẮN - 2 ├── PY01007 - LÃI SUẤT NGÂN HÀNG ├── PY01008 - CHUYỂN THÀNH CHỮ HOA ├── PY01009 - CHỮ HOA – CHỮ THƯỜNG ├── PY01010 - ĐẦU CUỐI ├── PY01011 - LIỆT KÊ SỐ ĐẸP ├── PY01012 - CHÈN XÂU ├── PY01013 - ƯỚC SỐ CHUNG NGUYÊN TỐ ├── PY01014 - CHIA HẾT CHO K ├── PY01015 - SỐ KHÔNG GIẢM ├── PY01016 - GIẢI MÃ ├── PY01017 - MÃ HÓA 1 ├── PY01018 - MÃ HÓA 2 ├── PY01019 - KHOẢNG CÁCH KÝ TỰ ├── PY01020 - SỐ PHÁT LỘC ├── PY01021 - TÍNH TỔNG CÁC CHỮ SỐ ├── PY01022 - TỔNG CHỮ SỐ ├── PY01023 - PHÂN TÍCH THỪA SỐ NGUYÊN TỐ ├── PY01024 - CHẴN - LẺ ├── PY01025 - CHÈN DẤU PHẨY ├── PY01026 - SẮP ĐẶT LẠI XÂU KÝ TỰ ├── PY01027 - SỐ LỘC PHÁT ĐẸP ├── PY01028 - TÁCH TỪ ├── PY01029 - SỐ ĐẢO NGUYÊN TỐ CÙNG NHAU ├── PY01030 - NGUYÊN TỐ CÙNG NHAU ├── PY01031 - ĐỔI CƠ SỐ ├── PY01033 - BỘ BA NGUYÊN TỐ CÙNG NHAU ├── PY01034 - ĐỔI CHỖ CÁC CHỮ SỐ ├── PY01035 - HỆ CƠ SỐ 8 ├── PY01036 - TÍNH TỔNG PHÂN THỨC ├── PY01037 - SỐ PHẢN NGUYÊN TỐ NHỎ NHẤT ├── PY01038 - KIỂM TRA CHIA HẾT CHO 7 ├── PY01039 - KIỂM TRA SỐ ĐẸP ├── PY01040 - MÃ HÓA 3 ├── PY01041 - SỐ TĂNG GIẢM ├── PY01042 - KIỂM TRA HỆ CƠ SỐ 3 ├── PY01043 - SỐ THUẬN NGHỊCH CHẴN ├── PY01044 - XỬ LÝ XÂU KÝ TỰ ├── PY01045 - XÂU PALINDROME ├── PY01046 - THÁP HÀ NỘI ├── PY01047 - KIỂM TRA NGUYÊN TỐ ├── PY01048 - TỔNG LIÊN TIẾP ├── PY01049 - CHỮ SỐ NGUYÊN TỐ ├── PY01050 - KÝ TỰ A – B – C ├── PY01051 - TỔNG CHỮ SỐ THUẬN NGHỊCH ├── PY01052 - TỔNG CHỮ SỐ NGUYÊN TỐ ├── PY01053 - SỐ CHIA HẾT CHO 3 ├── PY01054 - TÍCH CHỮ SỐ ├── PY01055 - SỐ XEN KẼ ├── PY01056 - CHẴN – LẺ - NGUYÊN TỐ ├── PY01057 - VỊ TRÍ NGUYÊN TỐ ├── PY01058 - ĐOẠN CUỐI NGUYÊN TỐ ├── PY01059 - TỔNG CHỮ SỐ - TÍCH CHỮ SỐ ├── PY01060 - TÍCH CHỮ SỐ - TỔNG CHỮ SỐ ├── PY01061 - ĐẦU CUỐI NGUYÊN TỐ ├── PY01062 - ƯU THẾ NGUYÊN TỐ ├── PY01063 - ĐẾM SỐ TRONG XÂU ├── PY01064 - KÝ TỰ THỨ K ├── PY01066 - XÂU “THĂNG BẰNG” ├── PY01067 - SỐ 2 ƯU THẾ ├── PY01068 - ĐẶT TÊN ├── PY01069 - CHỮ SỐ NGUYÊN TỐ ├── PY01071 - PYTHON FILE ├── PY01072 - BÀI TOÁN TỔ HỢP ├── PY01073 - HOÁN VỊ KÝ TỰ ├── PY01074 - TỔNG ƯỚC SỐ ├── PY01076 - SỐ NGUYÊN LỚN ├── PY02002 - LIỆT SỐ FIBONACCI ├── PY02003 - DÃY SỐ HAMMING ├── PY02004 - DÃY SỐ NHỊ PHÂN ├── PY02005 - CẶP NGHỊCH THẾ ├── PY02006 - DÃY SỐ PHÙ HỢP ├── PY02007 - CHIA DƯ CHO 42 ├── PY02008 - KHOẢNG CÁCH NGUYÊN TỐ ├── PY02009 - TRÚNG THƯỞNG ├── PY02010 - LỚN NHẤT VÀ NHỎ NHẤT ├── PY02011 - BIẾN ĐỔI VỀ DÃY BẰNG NHAU ├── PY02012 - SẮP XẾP CHẴN LẺ ├── PY02013 - BIẾN ĐỔI VỀ 1 ├── PY02014 - BIẾN ĐỔI NGUYÊN TỐ ├── PY02015 - BIẾN ĐỔI DÃY SỐ ├── PY02016 - XUẤT HIỆN NHIỀU LẦN NHẤT ├── PY02017 - TÂN SUẤT LẺ ├── PY02018 - SỐ NHỎ NHẤT CÒN THIẾU ├── PY02019 - NGUYÊN TỐ CÙNG NHAU ├── PY02020 - TÍNH ĐIỂM TRUNG BÌNH ├── PY02021 - DÃY CON CHUNG CỦA BA DÃY SỐ ├── PY02022 - LIỆT KÊ SỐ NGUYÊN TỐ TRONG DÃY ├── PY02023 - SẮP XẾP THEO TỔNG CHỮ SỐ ├── PY02024 - SẮP XẾP THEO TÍCH CHỮ SỐ ├── PY02025 - TẬP HỢP SỐ NGUYÊN ├── PY02026 - TẬP HỢP SỐ BẰNG NHAU ├── PY02027 - TÁCH SỐ VÀ SẮP XẾP ├── PY02028 - SẮP XẾP NGUYÊN TỐ ├── PY02029 - BẦU CỬ ├── PY02030 - PHÂN CHIA NGUYÊN TỐ ├── PY02031 - KIỂM TRA NGUYÊN TỐ ├── PY02032 - LIỆT KÊ CÁC SỐ CÓ HAI CHỮ SỐ TĂNG DẦN ├── PY02033 - LIỆT KÊ CÁC SỐ CÓ HAI CHỮ SỐ THEO THỨ TỰ XUẤT HIỆN ├── PY02034 - ĐẾM CÁC SỐ CÓ HAI CHỮ SỐ ├── PY02035 - NGƯỠNG TỐI THIỂU ├── PY02036 - LIỆT KÊ CẶP SỐ NGUYÊN TỐ CÙNG NHAU ├── PY02038 - ĐẾM CẶP ĐỒNG XU ├── PY02039 - MA TRẬN - 1 ├── PY02040 - MA TRẬN - 2 ├── PY02041 - TỔNG SỐ NGUYÊN LỚN ├── PY02042 - HIỆU SỐ NGUYÊN LỚN ├── PY02043 - ĐẾM SỐ TRONG XÂU ├── PY02045 - TÁCH ĐÔI VÀ TÍNH TỔNG ├── PY02046 - PHÂN CHIA NGUYÊN TỐ ├── PY02048 - TÁCH NHÓM TỐI ƯU ├── PY02049 - ƯỚC SỐ CỦA GIAI THỪA ├── PY02050 - ĐOẠN LIÊN TIẾP NHỎ HƠN ├── PY02051 - KHÔI PHỤC DÃY SỐ ├── PY02052 - TÍNH CÂN ĐỐI CỦA MA TRẬN - 1 ├── PY02053 - TÍNH CÂN ĐỐI CỦA MA TRẬN - 2 ├── PY02054 - BIẾN ĐỔI VỀ MA TRẬN VUÔNG ├── PY02055 - SỐ NGUYÊN TỐ LỚN NHẤT TRONG MA TRẬN ├── PY02056 - SỐ THUẬN NGHỊCH LỚN NHẤT TRONG MA TRẬN ├── PY02057 - SỐ MAY MẮN TRONG MA TRẬN ├── PY02058 - SỐ ĐẸP TRONG MA TRẬN ├── PY02059 - SỐ NGUYÊN TỐ TRONG MA TRẬN ├── PY02061 - TÍNH TÍCH CHẬP MA TRẬN ├── PY02063 - TÍCH LỚN NHẤT ├── PY02065 - DIỆN TÍCH TOÀN PHẦN ├── PY02066 - BÀI TOÁN ĐẾM ├── PY02067 - DÃY SỐ TƯƠNG THÍCH ├── PY02068 - XỬ LÝ ẢNH ├── PY02069 - SỐ THUẬN NGHỊCHTRONG MA TRẬN ├── PY02071 - TỔNG CÁC SỐ TỰ NHIÊN ├── PY02072 - ĐOẠN CON TRUNG BÌNH LỚN NHẤT ├── PY02073 - KÝ TỰ GIỐNG NHAU ├── PY02075 - TRỤC TỌA ĐỘ ├── PY02078 - TĂNG - GIẢM ├── PY03004 - THỐNG KÊ TỪ KHÁC NHAU ├── PY03005 - THỐNG KÊ TỪ KHÁC NHAU THEO NGƯỠNG K ├── PY03006 - THỐNG KÊ TỪ KHÁC NHAU KHÔNG CHỨA CHỮ SỐ ├── PY03007 - XỬ LÝ VĂN BẢN ├── PY03008 - ĐỒ THỊ HÌNH SAO ├── PY03012 - BẢNG XẾP HẠNG ├── PY03014 - BIỂU THỨC ├── PY04001 - LỚP POINT ├── PY04002 - LỚP RECTANGLE ├── PY04003 - LỚP PHÂN SỐ - 1 ├── PY04004 - LỚP PHÂN SỐ - 2 ├── PY04005 - LỚP TRIANGLE - 1 ├── PY04006 - LỚP TRIANGLE - 2 ├── PY04007 - LỚP MATRIX - 1 ├── PY04009 - LỚP SỐ PHỨC ├── PY04010 - LỚP THÍ SINH - 1 ├── PY04012 - TÍNH ĐIỂM CHUYÊN CẦN ├── PY04013 - TÍNH TOÁN LƯỢNG MƯA ├── PY04014 - BẢNG ĐIỂM ├── PY04015 - LẬP HÓA ĐƠN - 1 ├── PY04016 - LẬP HÓA ĐƠN - 2 ├── PY04017 - TÍNH VẬN TỐC ├── PY04018 - XÁC ĐỊNH TRÚNG TUYỂN ├── PY04019 - TUYỂN NHÂN VIÊN ├── PY04020 - LẬP HÓA ĐƠN - 3 ├── PY04021 - TÍNH TOÁN THỜI GIAN ├── PYKT037 - ĐỔI CƠ SỐ ├── PYKT038 - HỆ CƠ SỐ 8 ├── PYKT039 - DÃY SỐ PHÙ HỢP ├── PYKT041 - ĐẾM CẶP ĐỒNG XU ├── PYKT058 - ĐỈNH THẮT ├── PYKT059 - THÀNH PHẦN LIÊN THÔNG ├── PYKT067 - HOÁN VỊ NGƯỢC ├── PYKT068 - DANH SÁCH MÔN THI ├── PYKT072 - XOAY VÒNG XÂU KÝ TỰ ├── PYKT073 - XÁC ĐỊNH THỂ LOẠI THƠ ├── PYKT074 - GỬI THÔNG BÁO ├── PYKT075 - SAO CHÉP DANH BẠ ├── PYKT076 - DANH SÁCH PHIM ├── PYKT077 - LỊCH THI HỌC KỲ ├── PYKT078 - SẮP XẾP DÃY SỐ ├── PYKT079 - ĐIỀN SỐ ├── PYKT080 - THỐNG KÊ DỊCH TỄ ├── PYKT081 - ĐỊA CHỈ IP ├── PYKT082 - TÍNH ĐIỂM THI IELTS ├── PYKT083 - THU PHÍ XE Ô TÔ ├── PYKT084 - CÂU HỎI THEO CHỦ ĐỀ - 1 ├── PYKT085 - CÂU HỎI THEO CHỦ ĐỀ - 2 ├── PYKT086 - CHUYỂN ĐỔI NHỊ PHÂN ├── PYKT087 - SỐ ĐẶC BIỆT ├── PYKT088 - SỐ CÓ 9 ƯỚC SỐ ├── PYKT089 - SẮP XẾP CHẴN LẺ ├── PYKT090 - DANH SÁCH EMAIL ├── PYKT091 - TÌM TỪ THUẬN NGHỊCH DÀI NHẤT ├── PYKT093 - TÍNH ĐIỂM TRUNG BÌNH ├── PYKT096 - DANH SÁCH THI LẬP TRÌNH ├── PYKT098 - LOẠI BỎ SỐ NGUYÊN └── PYKT2049 - BÌNH THÔNG NHAU /ICPC0058 - ĐỈNH THẮT: -------------------------------------------------------------------------------- 1 | def check(n, k, u, v, ke) : 2 | q, a = [u], [0] * (n + 1) 3 | a[u] = 1 4 | while len(q) > 0 : 5 | x = q.pop() 6 | if x == v : return False 7 | for i in ke[x] : 8 | if a[i] == 0 and i != k : 9 | q.append(i) 10 | a[i] = 1 11 | return True 12 | 13 | for t in range(int(input())) : 14 | n, m, u, v = [int(x) for x in input().split()] 15 | ke = [] 16 | for i in range(n + 1) : ke.append([]) 17 | for i in range(m) : 18 | x, y = [int(x) for x in input().split()] 19 | ke[x].append(y) 20 | ans = 0 21 | for i in range(1, n + 1) : 22 | if i != u and i != v : 23 | if check(n, i, u, v, ke) : ans += 1 24 | print(ans) 25 | -------------------------------------------------------------------------------- /ICPC0101 - THU GỌN DÃY SỐ: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = [int(x) for x in input().split()] 3 | b = [] 4 | for i in a: 5 | if len(b) == 0: 6 | b = b + [i] 7 | else: 8 | if (b[-1] + i) % 2 == 0: 9 | b.pop() 10 | else: 11 | b = b + [i] 12 | print(len(b)) 13 | -------------------------------------------------------------------------------- /ICPC0104 - TÌM SỐ NHỎ NHẤT: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n = input() 4 | n = n + 'z' 5 | ans = 10 ** 20 6 | s = 0 7 | for i in range(len(n)) : 8 | if n[i].isalpha() : 9 | if i != 0 and n[i - 1].isdigit() : ans = min(ans, s) 10 | s = 0 11 | else : s = s * 10 + int(n[i]) 12 | print(ans) 13 | -------------------------------------------------------------------------------- /ICPC0105 - TÌM SỐ LỚN NHẤT: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n = input() 4 | n = n + 'z' 5 | ans = 0 6 | s = 0 7 | for i in range(len(n)) : 8 | if n[i].isalpha() : 9 | if i != 0 and n[i - 1].isdigit() : ans = max(ans, s) 10 | s = 0 11 | else : s = s * 10 + int(n[i]) 12 | print(ans) 13 | -------------------------------------------------------------------------------- /ICPC0106 - ĐỔI CƠ SỐ - 2: -------------------------------------------------------------------------------- 1 | import math 2 | f = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] 3 | t = int(input()) 4 | for i in range(t) : 5 | n = int(input()) 6 | a = input() 7 | n = int(math.log(n)/math.log(2)) 8 | while len(a) % n != 0 : a = '0' + a 9 | for i in range(0, len(a), n) : 10 | s = 0 11 | for j in range(i, i + n): 12 | if a[j] == '1' : s += pow(2, n - j + i - 1) 13 | print(f[s],end = "") 14 | print() 15 | -------------------------------------------------------------------------------- /ICPC0107 - THAY ĐỔI CHỮ SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | m, n = [x for x in input().split()] 4 | a = input().strip() 5 | if(a.count(' ')) : a, b = a.split() 6 | else : b = input() 7 | p = min(m, n) 8 | q = max(m, n) 9 | print(int(a.replace(q, p)) + int(b.replace(q, p)), end=" ") 10 | print(int(a.replace(p, q)) + int(b.replace(p, q))) 11 | -------------------------------------------------------------------------------- /ICPC0108 - SUM TRIPLE ZERO: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for k in range(0,t): 5 | n = int(input()) 6 | a = sorted([int(x) for x in input().split()]) 7 | s = 0 8 | for i in range(0, n - 2) : 9 | l = i + 1 10 | r = len(a) - 1 11 | x = a[i] 12 | while l < r : 13 | if x + a[l] + a[r] == 0: 14 | s += 1 15 | l += 1 16 | elif x + a[l] + a[r] < 0 : 17 | l += 1 18 | else: 19 | r -= 1 20 | print(s) 21 | -------------------------------------------------------------------------------- /ICPC0109 - MIN TRIPLE: -------------------------------------------------------------------------------- 1 | import heapq 2 | import re 3 | 4 | t = int(input()) 5 | for z in range(t) : 6 | n = int(input()) 7 | main = ' ' + input().replace(' ', ' ') + ' ' 8 | a = [] 9 | i = -8 10 | while i < 9 and len(a) < 4: 11 | s = '\d' * abs(i) + ' ' 12 | if i < 0 : 13 | s = '-' + s 14 | elif i > 0 : 15 | s = ' ' + s 16 | else : 17 | i += 1 18 | continue 19 | a += [int(x) for x in re.findall(s, main)] 20 | i += 1 21 | ans = 0 22 | for x in heapq.nsmallest(3, a): 23 | ans += x 24 | print(ans) 25 | # ඞ 26 | 27 | ''' Do Xuan Huong ඞ 28 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀ 29 | ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠙⠛⠛⠛⠛⠻⢿⣿⣷⣤⡀⠀⠀⠀⠀⠀ 30 | ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠈⢻⣿⣿⡄⠀⠀⠀⠀ 31 | ⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⠀⣠⣶⣾⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣄⠀⠀⠀ 32 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀⢰⣿⣿⣯⠁⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣷⡄⠀ 33 | ⠀⠀⣀⣤⣴⣶⣶⣿⡟⠀⠀⠀⢸⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⠀ 34 | ⠀⢰⣿⡟⠋⠉⣹⣿⡇⠀⠀⠀⠘⣿⣿⣿⣿⣷⣦⣤⣤⣤⣶⣶⣶⣶⣿⣿⣿⠀ 35 | ⠀⢸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀ 36 | ⠀⣸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠉⠻⠿⣿⣿⣿⣿⡿⠿⠿⠛⢻⣿⡇⠀⠀ 37 | ⠀⣿⣿⠁⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣧⠀⠀ 38 | ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀ 39 | ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀ 40 | ⠀⢿⣿⡆⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡇⠀⠀ 41 | ⠀⠸⣿⣧⡀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠃⠀⠀ 42 | ⠀⠀⠛⢿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⣰⣿⣿⣷⣶⣶⣶⣶⠶⠀⢠⣿⣿⠀⠀⠀ 43 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⣽⣿⡏⠁⠀⠀⢸⣿⡇⠀⠀⠀ 44 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀ 45 | ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀ 46 | ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 47 | ''' 48 | -------------------------------------------------------------------------------- /ICPC0111 - XOAY MẢNG: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(1, t+1): 3 | [n, k] = [int(x) for x in input().split()] 4 | a = [int(x) for x in input().split()] 5 | for i in range(k , n ): print(a[i], end = " ") 6 | for i in range(0, k): print(a[i], end = " ") 7 | print() 8 | -------------------------------------------------------------------------------- /ICPC0112 - PRIME – TRIPLET: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = [0] * 1000001 4 | 5 | def era() : 6 | a[0] = a[1] = 1 7 | for i in range(2, 1000) : 8 | if a[i] == 0 : 9 | for j in range(i * i, 1000001, i) : a[j] = 1 10 | 11 | era() 12 | t = int(input()) 13 | for i in range(t) : 14 | n = int(input()) 15 | s = 0 16 | for i in range(6, n) : 17 | if a[i] == 0 and a[i - 6] == 0 and (a[i - 2] == 0 or a[i - 4] == 0) : s += 1 18 | print(s) 19 | -------------------------------------------------------------------------------- /ICPC0113 - EMIRP NUMBER: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = [0] * 1000001 4 | 5 | def era() : 6 | a[0] = a[1] = 1 7 | for i in range(2, 1000) : 8 | if a[i] == 0 : 9 | for j in range(i * i, 1000001, i) : a[j] = 1 10 | 11 | era() 12 | t = int(input()) 13 | for i in range(t) : 14 | n = int(input()) 15 | for i in range(1, n) : 16 | k = int(str(i)[::-1]) 17 | if k > i and k < n and a[i] == 0 and a[k] == 0 : 18 | print(i, k, end = ' ') 19 | print() 20 | -------------------------------------------------------------------------------- /ICPC0114 - PERFECT PRIME: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | def check(n) : 8 | m = 0 9 | s = 0 10 | x = n 11 | while n != 0 : 12 | k = n % 10 13 | if nto(k) == False : return False 14 | m = m * 10 + k 15 | s += k 16 | n = int(n / 10) 17 | if nto(s) and nto(x) and nto(m) : return True 18 | return False 19 | t = int(input()) 20 | for i in range(t) : 21 | n = int(input()) 22 | if check(n) == True : print("Yes") 23 | else : print("No") 24 | -------------------------------------------------------------------------------- /ICPC0115 - SỐ KRISH: -------------------------------------------------------------------------------- 1 | def giaithua(n) : 2 | s = 1 3 | for i in range(n) : 4 | s *= i + 1 5 | return s 6 | def check(n) : 7 | s = 0 8 | m = n 9 | while n > 0 : 10 | s += giaithua(n % 10) 11 | n = int(n / 10) 12 | if s == m : return True 13 | else : return False 14 | t = int(input()) 15 | for i in range(t) : 16 | n = int(input()) 17 | if check(n) : print("Yes") 18 | else : print("No") 19 | -------------------------------------------------------------------------------- /ICPC0116 - CON SỐ DUYÊN NỢ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | if s[0] == s[-1] : print("YES") 5 | else : print("NO") 6 | -------------------------------------------------------------------------------- /ICPC0117 - CHÚC MỪNG NĂM MỚI: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = {"-1"} 3 | for i in range(n) : 4 | x = input() 5 | m.add(x) 6 | print(len(m) - 1) 7 | -------------------------------------------------------------------------------- /ICPC0118 - CUNG HOÀNG ĐẠO: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | d, m = [int(x) for x in input().split()] 4 | if m == 1 : 5 | if d < 20 : 6 | print("Ma Ket") 7 | else : 8 | print("Bao Binh") 9 | elif m == 2 : 10 | if d < 19 : 11 | print("Bao Binh") 12 | else : 13 | print("Song Ngu") 14 | elif m == 3 : 15 | if d < 21 : 16 | print("Song Ngu") 17 | else : 18 | print("Bach Duong") 19 | elif m == 4 : 20 | if d < 20 : 21 | print("Bach Duong") 22 | else : 23 | print("Kim Nguu") 24 | elif m == 5 : 25 | if d < 21 : 26 | print("Kim Nguu") 27 | else : 28 | print("Song Tu") 29 | elif m == 6 : 30 | if d < 21 : 31 | print("Song Tu") 32 | else : 33 | print("Cu Giai") 34 | elif m == 7 : 35 | if d < 23 : 36 | print("Cu Giai") 37 | else : 38 | print("Su Tu") 39 | elif m == 8 : 40 | if d < 23 : 41 | print("Su Tu") 42 | else : 43 | print("Xu Nu") 44 | elif m == 9 : 45 | if d < 23 : 46 | print("Xu Nu") 47 | else : 48 | print("Thien Binh") 49 | elif m == 10 : 50 | if d < 23 : 51 | print("Thien Binh") 52 | else : 53 | print("Thien Yet") 54 | elif m == 11 : 55 | if d < 23 : 56 | print("Thien Yet") 57 | else : 58 | print("Nhan Ma") 59 | else : 60 | if d < 22 : 61 | print("Nhan Ma") 62 | else : 63 | print("Ma Ket") 64 | -------------------------------------------------------------------------------- /PY00000 - Welcome to python: -------------------------------------------------------------------------------- 1 | print("Welcome to python.") 2 | -------------------------------------------------------------------------------- /PY01000 - HELLO: -------------------------------------------------------------------------------- 1 | a = input() 2 | print("Hello " + a + "!") 3 | -------------------------------------------------------------------------------- /PY01001 - KIỂM TRA CHẴN LẺ: -------------------------------------------------------------------------------- 1 | a = int(input()) 2 | if a % 2 == 0 : print("CHAN") 3 | else : print("LE") 4 | -------------------------------------------------------------------------------- /PY01002 - PHÉP CỘNG: -------------------------------------------------------------------------------- 1 | a = input().split() 2 | if int(a[0]) + int(a[2]) == int(a[4]) : print("YES") 3 | else : print("NO") 4 | -------------------------------------------------------------------------------- /PY01003 - LÀM TRÒN SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | ans = "" 5 | ok = 1 6 | for i in range(1, len(s)) : 7 | ans += "0" 8 | if ok == 0 : 9 | if int(s[-i]) > 3 : 10 | ok = 0 11 | else : 12 | ok = 1 13 | else : 14 | if int(s[-i]) > 4 : 15 | ok = 0 16 | else : 17 | ok = 1 18 | if ok == 0 : 19 | if int(s[0]) == 9 : 20 | ans += "0" 21 | ans = "1" + ans 22 | else : 23 | ans = chr(ord(s[0]) + 1) + ans 24 | else : ans = s[0] + ans 25 | print(ans) 26 | -------------------------------------------------------------------------------- /PY01004 - NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | t = int(input()) 8 | for i in range(t) : 9 | n = int(input()) 10 | s = 0 11 | for i in range(1, n) : 12 | if math.gcd(i, n) == 1 : s += 1 13 | if nto(s) == True : print("YES") 14 | else : print("NO") 15 | -------------------------------------------------------------------------------- /PY01005 - SỐ MAY MẮN: -------------------------------------------------------------------------------- 1 | a = input() 2 | s = 0 3 | for i in a : 4 | if i == '4' or i == '7' : s += 1 5 | if s == 4 or s == 7 : print("YES") 6 | else : print("NO") 7 | -------------------------------------------------------------------------------- /PY01006 - SỐ MAY MẮN - 2: -------------------------------------------------------------------------------- 1 | def check(a): 2 | for i in a: 3 | if i != '4' and i != '7' : return False 4 | return True 5 | t = int(input()) 6 | for i in range(t): 7 | s = input() 8 | if check(s) == True : print("YES") 9 | else : print("NO") 10 | -------------------------------------------------------------------------------- /PY01007 - LÃI SUẤT NGÂN HÀNG: -------------------------------------------------------------------------------- 1 | import math 2 | t = int(input()) 3 | for i in range(t) : 4 | n, x, m = [float(x) for x in input().split()] 5 | x /= 100 6 | s = math.log(m / n, 1 + x) 7 | if s != int(s) : s = s + 1 8 | print(int(s)) 9 | -------------------------------------------------------------------------------- /PY01008 - CHUYỂN THÀNH CHỮ HOA: -------------------------------------------------------------------------------- 1 | s = input() 2 | print(s.upper()) 3 | -------------------------------------------------------------------------------- /PY01009 - CHỮ HOA – CHỮ THƯỜNG: -------------------------------------------------------------------------------- 1 | s = input() 2 | s1 = 0 3 | s2 = 0 4 | for i in s : 5 | if i.isupper() : s1 += 1 6 | else : s2 += 1 7 | if s1 > s2 : print(s.upper()) 8 | else : print(s.lower()) 9 | -------------------------------------------------------------------------------- /PY01010 - ĐẦU CUỐI: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | if s[0] == s[-2] and s[1] == s[-1] : print("YES") 5 | else : print("NO") 6 | -------------------------------------------------------------------------------- /PY01011 - LIỆT KÊ SỐ ĐẸP: -------------------------------------------------------------------------------- 1 | a = [] 2 | b = ['0', '2', '4', '6', '8'] 3 | def Try(s) : 4 | k = list(s) 5 | k.reverse() 6 | k = int(s + ''.join(k)) 7 | global a 8 | a = a + [k] 9 | if(len(s) != 3) : 10 | for i in b : 11 | Try(s + i) 12 | for i in range(1, 5) : Try(b[i]) 13 | a.sort() 14 | t = int(input()) 15 | for i in range(t) : 16 | n = int(input()) 17 | for j in a : 18 | if j < n : print(j, end = " ") 19 | else : break 20 | print() 21 | -------------------------------------------------------------------------------- /PY01012 - CHÈN XÂU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = input() 4 | b = input() 5 | p = int(input()) - 1 6 | print(a[:p:] + b + a[p::]) 7 | -------------------------------------------------------------------------------- /PY01013 - ƯỚC SỐ CHUNG NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | t = int(input()) 8 | for i in range(t) : 9 | a, b = [int(x) for x in input().split()] 10 | c = math.gcd(a, b) 11 | s = 0 12 | while c > 0 : 13 | s += c % 10 14 | c = int(c / 10) 15 | if nto(s) == True : print("YES") 16 | else : print("NO") 17 | -------------------------------------------------------------------------------- /PY01014 - CHIA HẾT CHO K: -------------------------------------------------------------------------------- 1 | a, k, n = [int(x) for x in input().split()] 2 | b = k - a % k + a 3 | ok = 0 4 | for i in range(b, n + 1, k) : 5 | ok = 1 6 | print(i - a, end = " ") 7 | if ok == 0 : print("-1") 8 | -------------------------------------------------------------------------------- /PY01015 - SỐ KHÔNG GIẢM: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | n = len(s) 3 | for i in range(1, n) : 4 | if s[i - 1] > s[i] : return False 5 | return True 6 | t = int(input()) 7 | for i in range(t) : 8 | s = input() 9 | if check(s) == True : print("YES") 10 | else : print("NO") 11 | -------------------------------------------------------------------------------- /PY01016 - GIẢI MÃ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | for i in range(0, len(s), 2) : 5 | for j in range(0, int(s[i+1])) : 6 | print(s[i], end ="") 7 | print() 8 | -------------------------------------------------------------------------------- /PY01017 - MÃ HÓA 1: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | n = len(s) 5 | k = 1 6 | for i in range(1, n) : 7 | if s[i] != s[i - 1] : 8 | print(k,end = "") 9 | print(s[i - 1], end = "") 10 | k = 1 11 | else : k += 1 12 | print(k, end = "") 13 | print(s[n - 1]) 14 | -------------------------------------------------------------------------------- /PY01018 - MÃ HÓA 2: -------------------------------------------------------------------------------- 1 | p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_." 2 | while True : 3 | ip = input() 4 | if ip == "0" : break 5 | k, s = ip.split() 6 | k = int(k) 7 | n = "" 8 | for i in s : 9 | x = 0 10 | for j in p : 11 | if i == j : 12 | break 13 | x += 1 14 | x = (x + k) % 28 15 | n = p[x] + n 16 | print(n) 17 | -------------------------------------------------------------------------------- /PY01019 - KHOẢNG CÁCH KÝ TỰ: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | x = "" 3 | for i in s : x = i + x 4 | for i in range(1, len(s)) : 5 | if abs(ord(s[i]) - ord(s[i - 1])) != abs(ord(x[i]) - ord(x[i - 1])) : return False 6 | return True 7 | t = int(input()) 8 | for i in range(t) : 9 | s = input() 10 | if check(s) == True : print("YES") 11 | else : print("NO") 12 | -------------------------------------------------------------------------------- /PY01020 - SỐ PHÁT LỘC: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t): 3 | s = input() 4 | if len(s) < 2 : print("NO") 5 | else : 6 | if s[-2] == '8' and s[-1] == '6' : print("YES") 7 | else : print("NO") 8 | -------------------------------------------------------------------------------- /PY01021 - TÍNH TỔNG CÁC CHỮ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | a = input() 6 | d = 0 7 | s = "" 8 | for i in a : 9 | if i.isdigit() : d += int(i) 10 | else : s += i 11 | print(''.join(sorted(s)), d, sep = "") 12 | -------------------------------------------------------------------------------- /PY01022 - TỔNG CHỮ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def trans(s) : 4 | n = 0 5 | for i in s : n += ord(i) - ord('0') 6 | return str(n) 7 | 8 | s = input() 9 | d = 0 10 | while(len(s) > 1) : 11 | s = trans(s) 12 | d += 1 13 | print(d) 14 | -------------------------------------------------------------------------------- /PY01023 - PHÂN TÍCH THỪA SỐ NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | t = int(input()) 3 | for i in range(t) : 4 | n = int(input()) 5 | print("1", end = "") 6 | for i in range(2, int(math.sqrt(n)) + 1) : 7 | s = 0 8 | while n % i == 0 : 9 | s += 1 10 | n /= i 11 | if s != 0 : 12 | print(" * ", end = "") 13 | print(i, end = "^") 14 | print(s, end = "") 15 | if n > 1 : 16 | print(" * ", end = "") 17 | print(int(n), end = "^1") 18 | print() 19 | -------------------------------------------------------------------------------- /PY01024 - CHẴN - LẺ: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | n = int(s) 3 | m = 0 4 | while n > 0 : 5 | m += n % 10 6 | n = int(n / 10) 7 | if m % 10 != 0 : return False 8 | for i in range(1, len(s)) : 9 | if abs(int(s[i]) - int(s[i - 1])) != 2 : return False 10 | return True 11 | t = int(input()) 12 | for i in range(t) : 13 | s = input() 14 | if check(s) == True : print("YES") 15 | else : print("NO") 16 | -------------------------------------------------------------------------------- /PY01025 - CHÈN DẤU PHẨY: -------------------------------------------------------------------------------- 1 | s = input() 2 | ans = "" 3 | k = -2 4 | for i in range(len(s)) : 5 | ans = s[-i - 1] + ans 6 | if k % 3 == 0 : ans = "," + ans 7 | k += 1 8 | print(ans.strip(',')) 9 | -------------------------------------------------------------------------------- /PY01026 - SẮP ĐẶT LẠI XÂU KÝ TỰ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for i in range(t) : 5 | print("Test ", i + 1, ": ", sep = "", end = "") 6 | a = sorted(input()) 7 | b = sorted(input()) 8 | if a == b : print("YES") 9 | else : print("NO") 10 | -------------------------------------------------------------------------------- /PY01027 - SỐ LỘC PHÁT ĐẸP: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def check(s) : 4 | if s[0] != '6' : return 0 5 | for i in range(len(s)) : 6 | if s[i] != '6' and s[i] != '8' : return 0 7 | if i >= 2 and s[i - 2:i + 1:] == '888' : return 0 8 | return 1 9 | 10 | s = input() 11 | if check(s) == 1 : print("YES") 12 | else : print("NO") 13 | -------------------------------------------------------------------------------- /PY01028 - TÁCH TỪ: -------------------------------------------------------------------------------- 1 | a = input().split() 2 | for i in a : 3 | print(i) 4 | -------------------------------------------------------------------------------- /PY01029 - SỐ ĐẢO NGUYÊN TỐ CÙNG NHAU: -------------------------------------------------------------------------------- 1 | import math 2 | t = int(input()) 3 | for i in range(t) : 4 | s = input() 5 | x = "" 6 | for i in s : x = i + x 7 | if math.gcd(int(s), int(x)) == 1 : print("YES") 8 | else : print("NO") 9 | -------------------------------------------------------------------------------- /PY01030 - NGUYÊN TỐ CÙNG NHAU: -------------------------------------------------------------------------------- 1 | import math 2 | n, k = [int(x) for x in input().split()] 3 | a = 10**(k-1) 4 | b = 10**k 5 | x = 1 6 | for i in range(a, b) : 7 | if math.gcd(i, n) == 1 : 8 | print(i, end = " ") 9 | if x % 10 == 0 : print() 10 | x += 1 11 | -------------------------------------------------------------------------------- /PY01031 - ĐỔI CƠ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | f = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 4 | t = int(input()) 5 | for i in range(t): 6 | n, k = [int(x) for x in input().split()] 7 | s = '' 8 | while (n > 0): 9 | x = n % k 10 | s = f[x] + s 11 | n = int(n / k) 12 | print(s) 13 | -------------------------------------------------------------------------------- /PY01033 - BỘ BA NGUYÊN TỐ CÙNG NHAU: -------------------------------------------------------------------------------- 1 | import math 2 | def check(a, b) : 3 | if math.gcd(a, b) == 1 : return True 4 | return False 5 | a, b = [int(x) for x in input().split()] 6 | b += 1 7 | for i in range(a, b) : 8 | for j in range(i + 1, b) : 9 | for k in range(j + 1, b): 10 | if check(i, j) and check(j, k) and check(i, k): 11 | print("(",end = "") 12 | print(i, end = ", ") 13 | print(j, end = ", ") 14 | print(k, end = ")\n") 15 | -------------------------------------------------------------------------------- /PY01034 - ĐỔI CHỖ CÁC CHỮ SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for k in range(t) : 3 | a = input() 4 | n, p , s = len(a), -1, '0' 5 | for i in range(n - 2, -1, -1) : 6 | if a[i] > a[i + 1] : 7 | p = i 8 | break 9 | if p == -1 : 10 | print(-1) 11 | continue 12 | q = p + 1 13 | for i in range(p + 2, n) : 14 | if a[i] > s and a[i] > a[p + 1] and a[i] < a[p] : 15 | s = a[i] 16 | q = i 17 | a = a[:p:] + a[q] + a[p + 1:q:] + a[p] + a[q + 1::] 18 | if a[0] == '0' : print(-1) 19 | else : print(a) 20 | 21 | ''' Do Xuan Huong 22 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 26 | @@@@@@@@@@##########################################@@@@@@@@@ 27 | @@@@@@@@##############################################@@@@@@@ 28 | @@@@@@#################################################@@@@@@ 29 | @@@@@####################################################@@@@ 30 | @@@%#####################@@@@@@@@@@@######################@@@ 31 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 32 | @@##################@@@@@@ @@@@@@##################@@ 33 | @@#################@@@@@ @@@@###################@ 34 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 35 | @ &@@@@ @@@@ .......@@ 36 | @@ @@@@@@ @@@@@@ .......@@ 37 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 38 | @@@ @@@@@@@@@@@ ......@@@@ 39 | @@@@ ......@@@@@ 40 | @@@@@@ ......@@@@@@ 41 | @@@@@@@ .....@@@@@@@@ 42 | @@@@@@@@@ .....@@@@@@@@@@ 43 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 47 | ''' 48 | -------------------------------------------------------------------------------- /PY01035 - HỆ CƠ SỐ 8: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | print(oct(int(input(), 2))[2::]) 4 | -------------------------------------------------------------------------------- /PY01036 - TÍNH TỔNG PHÂN THỨC: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n = int(input()) 4 | s = 0 5 | k = 2 6 | if n % 2 == 1 : k = 1 7 | for i in range(k, n + 1, 2) : 8 | s += 1/i 9 | print("{:.6f}".format(s)) 10 | -------------------------------------------------------------------------------- /PY01037 - SỐ PHẢN NGUYÊN TỐ NHỎ NHẤT: -------------------------------------------------------------------------------- 1 | # Lazygarde ඞ 2 | # susssssssss ඞ 3 | import sys 4 | from bisect import bisect_left 5 | a = [1, 2, 4, 6, 12, 24, 36, 48, 60, 120, 180, 240, 360, 720, 840, 1260, 1680, 2520, 5040, 7560, 10080, 15120, 20160, 25200, 27720, 45360, 50400, 55440, 83160, 110880, 166320, 221760, 277200, 332640, 498960, 554400, 665280, 720720, 1081080, 1441440, 2162160, 2882880, 3603600, 4324320, 6486480, 7207200, 8648640, 10810800] 6 | t = int(input()) 7 | i = 0 8 | for line in sys.stdin : 9 | n = int(line) 10 | print(X[bisect_left(a, n)]) 11 | i += 1 12 | if i == t: break 13 | # ඞ 14 | ''' Do Xuan Huong ඞ 15 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀ 16 | ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠙⠛⠛⠛⠛⠻⢿⣿⣷⣤⡀⠀⠀⠀⠀⠀ 17 | ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠈⢻⣿⣿⡄⠀⠀⠀⠀ 18 | ⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⠀⣠⣶⣾⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣄⠀⠀⠀ 19 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀⢰⣿⣿⣯⠁⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣷⡄⠀ 20 | ⠀⠀⣀⣤⣴⣶⣶⣿⡟⠀⠀⠀⢸⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⠀ 21 | ⠀⢰⣿⡟⠋⠉⣹⣿⡇⠀⠀⠀⠘⣿⣿⣿⣿⣷⣦⣤⣤⣤⣶⣶⣶⣶⣿⣿⣿⠀ 22 | ⠀⢸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀ 23 | ⠀⣸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠉⠻⠿⣿⣿⣿⣿⡿⠿⠿⠛⢻⣿⡇⠀⠀ 24 | ⠀⣿⣿⠁⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣧⠀⠀ 25 | ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀ 26 | ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀ 27 | ⠀⢿⣿⡆⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡇⠀⠀ 28 | ⠀⠸⣿⣧⡀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠃⠀⠀ 29 | ⠀⠀⠛⢿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⣰⣿⣿⣷⣶⣶⣶⣶⠶⠀⢠⣿⣿⠀⠀⠀ 30 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⣽⣿⡏⠁⠀⠀⢸⣿⡇⠀⠀⠀ 31 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀ 32 | ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀ 33 | ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 34 | ''' 35 | -------------------------------------------------------------------------------- /PY01038 - KIỂM TRA CHIA HẾT CHO 7: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n = int(input()) 4 | while n % 7 != 0 : 5 | n += int(str(n)[::-1]) 6 | print(n) 7 | -------------------------------------------------------------------------------- /PY01039 - KIỂM TRA SỐ ĐẸP: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | for i in range(2, len(s)) : 3 | if s[i] != s[i - 2] : return False 4 | return True 5 | t = int(input()) 6 | for i in range(t) : 7 | s = input() 8 | if check(s) == True : print("YES") 9 | else : print("NO") 10 | -------------------------------------------------------------------------------- /PY01040 - MÃ HÓA 3: -------------------------------------------------------------------------------- 1 | def Try(s) : 2 | d = 0 3 | x = '' 4 | for i in s : 5 | d += ord(i) - ord('A') 6 | for i in s : 7 | x += chr(((ord(i) - ord('A') + d) % 26 + ord('A'))) 8 | return x 9 | t = int(input()) 10 | for k in range(t) : 11 | s, x = input(), '' 12 | n = int(len(s) / 2) 13 | a, b = s[:n:], s[n::] 14 | a = Try(a) 15 | b = Try(b) 16 | for i in range(n) : 17 | x += chr(((ord(a[i]) - 2 * ord('A') + ord(b[i])) % 26 + ord('A'))) 18 | print(x) 19 | 20 | ''' Do Xuan Huong 21 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 25 | @@@@@@@@@@##########################################@@@@@@@@@ 26 | @@@@@@@@##############################################@@@@@@@ 27 | @@@@@@#################################################@@@@@@ 28 | @@@@@####################################################@@@@ 29 | @@@%#####################@@@@@@@@@@@######################@@@ 30 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 31 | @@##################@@@@@@ @@@@@@##################@@ 32 | @@#################@@@@@ @@@@###################@ 33 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 34 | @ &@@@@ @@@@ .......@@ 35 | @@ @@@@@@ @@@@@@ .......@@ 36 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 37 | @@@ @@@@@@@@@@@ ......@@@@ 38 | @@@@ ......@@@@@ 39 | @@@@@@ ......@@@@@@ 40 | @@@@@@@ .....@@@@@@@@ 41 | @@@@@@@@@ .....@@@@@@@@@@ 42 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 46 | ''' 47 | -------------------------------------------------------------------------------- /PY01041 - SỐ TĂNG GIẢM: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | if len(s) < 3 : return False 3 | if s[1] <= s[0] or s[-2] <= s[-1] : return False 4 | p1 = 1 5 | p2 = len(s) - 2 6 | while s[p1] > s[p1 - 1] and p1 < len(s) : p1 += 1 7 | while s[p2] > s[p2 + 1] and p2 >= 0 : p2 -= 1 8 | if p1 == p2 + 2 : return True 9 | else : return False 10 | t = int(input()) 11 | for i in range(t) : 12 | s = input() 13 | if check(s) == True : print("YES") 14 | else : print("NO") 15 | -------------------------------------------------------------------------------- /PY01042 - KIỂM TRA HỆ CƠ SỐ 3: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | for i in s : 3 | if i != '0' and i != '1' and i != '2' : return False 4 | return True 5 | t = int(input()) 6 | for i in range(t) : 7 | s = input() 8 | if check(s) == True : print("YES") 9 | else : print("NO") 10 | -------------------------------------------------------------------------------- /PY01043 - SỐ THUẬN NGHỊCH CHẴN: -------------------------------------------------------------------------------- 1 | a = [] 2 | b = ['0', '2', '4', '6', '8'] 3 | def Try(s) : 4 | k = list(s) 5 | k.reverse() 6 | k = int(s + ''.join(k)) 7 | global a 8 | a = a + [k] 9 | if(len(s) != 3) : 10 | for i in b : 11 | Try(s + i) 12 | for i in range(1, 5) : Try(b[i]) 13 | a.sort() 14 | t = int(input()) 15 | for i in range(t) : 16 | n = int(input()) 17 | for j in a : 18 | if j < n : print(j, end = " ") 19 | else : break 20 | print() 21 | -------------------------------------------------------------------------------- /PY01044 - XỬ LÝ XÂU KÝ TỰ: -------------------------------------------------------------------------------- 1 | a = [i.lower() for i in input().split(' ')] 2 | b = [i.lower() for i in input().split(' ')] 3 | m1, m2, m3 = {}, {}, {} 4 | for i in a : 5 | m1[i] = 1 6 | m2[i] = 1 7 | for i in b : 8 | m1[i] = 1 9 | m3[i] = 1 10 | for i in sorted(list(m1)) : print(i, end = ' ') 11 | print() 12 | for i in sorted(list(m2)) : 13 | if i in m3 : print(i, end = ' ') 14 | -------------------------------------------------------------------------------- /PY01045 - XÂU PALINDROME: -------------------------------------------------------------------------------- 1 | s = input() 2 | print(len(s) - 1) 3 | -------------------------------------------------------------------------------- /PY01046 - THÁP HÀ NỘI: -------------------------------------------------------------------------------- 1 | def Try(n, a, b, c): 2 | if n == 1 : 3 | print(a, "->", b) 4 | return 5 | Try(n - 1, a, c, b) 6 | print(a,"->",b) 7 | Try(n - 1, c, b, a) 8 | n = int(input()) 9 | Try(n, 'A', 'C', 'B') 10 | -------------------------------------------------------------------------------- /PY01047 - KIỂM TRA NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | t = int(input()) 8 | for i in range(t) : 9 | s = input() 10 | if nto(int(s[-4::])) == True : print("YES") 11 | else : print("NO") 12 | -------------------------------------------------------------------------------- /PY01048 - TỔNG LIÊN TIẾP: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for k in range(t) : 3 | n, s = 2 * int(input()), 0 4 | for i in range(2, int(n ** 0.5) + 1) : 5 | if n % i == 0 : 6 | a, b = n / i, i 7 | k = a - b + 1 8 | if k % 2 == 0 : 9 | l = (a - b + 1) / 2 10 | r = a - l 11 | if r >= 1 and r > l : s += 1 12 | print(s) 13 | 14 | ''' Do Xuan Huong 15 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 19 | @@@@@@@@@@##########################################@@@@@@@@@ 20 | @@@@@@@@##############################################@@@@@@@ 21 | @@@@@@#################################################@@@@@@ 22 | @@@@@####################################################@@@@ 23 | @@@%#####################@@@@@@@@@@@######################@@@ 24 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 25 | @@##################@@@@@@ @@@@@@##################@@ 26 | @@#################@@@@@ @@@@###################@ 27 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 28 | @ &@@@@ @@@@ .......@@ 29 | @@ @@@@@@ @@@@@@ .......@@ 30 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 31 | @@@ @@@@@@@@@@@ ......@@@@ 32 | @@@@ ......@@@@@ 33 | @@@@@@ ......@@@@@@ 34 | @@@@@@@ .....@@@@@@@@ 35 | @@@@@@@@@ .....@@@@@@@@@@ 36 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 40 | ''' 41 | -------------------------------------------------------------------------------- /PY01049 - CHỮ SỐ NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | def check(n) : 8 | if nto(len(n)) == False : return False 9 | s1 = 0 10 | s2 = 0 11 | for i in n : 12 | if nto(int(i)) == True : s1 += 1 13 | else : s2 += 1 14 | if s1 > s2 : return True 15 | return False 16 | t = int(input()) 17 | for i in range(t) : 18 | n = input() 19 | if check(n) == True : print("YES") 20 | else : print("NO") 21 | -------------------------------------------------------------------------------- /PY01050 - KÝ TỰ A – B – C: -------------------------------------------------------------------------------- 1 | def Try(s, n, a, b, c) : 2 | if len(s) == n and a <= b and b <= c and a > 0 : print(s) 3 | if len(s) < n : 4 | Try(s + "A", n, a + 1, b, c) 5 | Try(s + "B", n, a, b + 1, c) 6 | Try(s + "C", n, a, b, c + 1) 7 | n = int(input()) 8 | for i in range(3, n + 1) : Try("", i, 0, 0, 0) 9 | -------------------------------------------------------------------------------- /PY01051 - TỔNG CHỮ SỐ THUẬN NGHỊCH: -------------------------------------------------------------------------------- 1 | def check(n) : 2 | s = 0 3 | for i in n : 4 | s += int(i) 5 | if s == int(str(s)[::-1]) and s > 10 : return True 6 | return False 7 | t = int(input()) 8 | for i in range(t) : 9 | n = input() 10 | if check(n) == True : print("YES") 11 | else : print("NO") 12 | -------------------------------------------------------------------------------- /PY01052 - TỔNG CHỮ SỐ NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | def check(n) : 8 | s = 0 9 | for i in n : 10 | s += int(i) 11 | if nto(s) : return True 12 | return False 13 | t = int(input()) 14 | for i in range(t) : 15 | n = input() 16 | if check(n) == True : print("YES") 17 | else : print("NO") 18 | -------------------------------------------------------------------------------- /PY01053 - SỐ CHIA HẾT CHO 3: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n = int(input()) 4 | if n % 3 == 0 : print("YES") 5 | else : print("NO") 6 | -------------------------------------------------------------------------------- /PY01054 - TÍCH CHỮ SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n = input() 4 | s = 1 5 | for i in n : 6 | if i != '0' : s *= int(i) 7 | print(s) 8 | -------------------------------------------------------------------------------- /PY01055 - SỐ XEN KẼ: -------------------------------------------------------------------------------- 1 | def check(s) : 2 | if len(s) % 2 == 0 or s[0] == s[1] : return False 3 | for i in range(2, len(s), 2) : 4 | if s[i] != s[0] : return False 5 | return True 6 | t = int(input()) 7 | for i in range(t) : 8 | s = input() 9 | if check(s) == True : print("YES") 10 | else : print("NO") 11 | -------------------------------------------------------------------------------- /PY01056 - CHẴN – LẺ - NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | def check(s) : 8 | x = 0 9 | for i in range(len(s)) : 10 | if (i % 2) != (int(s[i]) % 2) : return False 11 | x += int(s[i]) 12 | if nto(x) == True : return True 13 | else : return False 14 | t = int(input()) 15 | for i in range(t) : 16 | s = input() 17 | if check(s) == True : print("YES") 18 | else : print("NO") 19 | -------------------------------------------------------------------------------- /PY01057 - VỊ TRÍ NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | import math 3 | def nto(n) : 4 | if n < 2 : return 0 5 | for i in range(2, int(math.sqrt(n)) + 1) : 6 | if n % i == 0 : return 0 7 | return 1 8 | def check(s) : 9 | for i in range(len(s)) : 10 | if nto(i) != nto(int(s[i])) : return 0 11 | return 1 12 | t = int(input()) 13 | for i in range(t) : 14 | s = input() 15 | if check(s) == 1 : print("YES") 16 | else : print("NO") 17 | -------------------------------------------------------------------------------- /PY01058 - ĐOẠN CUỐI NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | import math 3 | def nto(n) : 4 | if n < 2 : return False 5 | for i in range(2, int(math.sqrt(n)) + 1) : 6 | if n % i == 0 : return False 7 | return True 8 | t = int(input()) 9 | for i in range(t) : 10 | s = input() 11 | if nto(int(s[-4::])) == True : print("YES") 12 | else : print("NO") 13 | -------------------------------------------------------------------------------- /PY01059 - TỔNG CHỮ SỐ - TÍCH CHỮ SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | s1 = 0 5 | s2 = 1 6 | ok = 0 7 | for i in range(len(s)) : 8 | if i % 2 == 0 : s1 += int(s[i]) 9 | else : 10 | if s[i] != '0' : 11 | ok = 1 12 | s2 *= int(s[i]) 13 | if ok == 0 : s2 = 0 14 | print(s1, s2) 15 | -------------------------------------------------------------------------------- /PY01060 - TÍCH CHỮ SỐ - TỔNG CHỮ SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | s = input() 4 | s1 = 1 5 | s2 = 0 6 | ok = 0 7 | for i in range(len(s)) : 8 | if i % 2 == 0 : 9 | if s[i] != '0' : 10 | ok = 1 11 | s1 *= int(s[i]) 12 | else : s2 += int(s[i]) 13 | if ok == 0 : s1 = 0 14 | print(s1, s2) 15 | -------------------------------------------------------------------------------- /PY01061 - ĐẦU CUỐI NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | t = int(input()) 8 | for i in range(t) : 9 | s = input() 10 | if nto(int(s[:3:])) and nto(int(s[-3::])) : print("YES") 11 | else : print("NO") 12 | -------------------------------------------------------------------------------- /PY01062 - ƯU THẾ NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return False 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return False 6 | return True 7 | def check(n) : 8 | if nto(len(n)) == False : return False 9 | s1 = 0 10 | s2 = 0 11 | for i in n : 12 | if nto(int(i)) == True : s1 += 1 13 | else : s2 += 1 14 | if s1 > s2 : return True 15 | return False 16 | t = int(input()) 17 | for i in range(t) : 18 | n = input() 19 | if check(n) == True : print("YES") 20 | else : print("NO") 21 | -------------------------------------------------------------------------------- /PY01063 - ĐẾM SỐ TRONG XÂU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for i in range(t) : 5 | s = input() 6 | n = input() 7 | print(len(s.split(n)) - 1) 8 | -------------------------------------------------------------------------------- /PY01064 - KÝ TỰ THỨ K: -------------------------------------------------------------------------------- 1 | def find(n, k) : 2 | if k == 2**(n - 1) : return n 3 | if k > 2**(n - 1) : return find(n - 1, k - 2**(n - 1)) 4 | return find(n - 1, k) 5 | 6 | t = int(input()) 7 | for i in range(t) : 8 | n, k = [int(x) for x in input().split()] 9 | print(chr(find(n, k) + ord('A') - 1)) 10 | 11 | ''' Do Xuan Huong 12 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 13 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 14 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 16 | @@@@@@@@@@##########################################@@@@@@@@@ 17 | @@@@@@@@##############################################@@@@@@@ 18 | @@@@@@#################################################@@@@@@ 19 | @@@@@####################################################@@@@ 20 | @@@%#####################@@@@@@@@@@@######################@@@ 21 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 22 | @@##################@@@@@@ @@@@@@##################@@ 23 | @@#################@@@@@ @@@@###################@ 24 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 25 | @ &@@@@ @@@@ .......@@ 26 | @@ @@@@@@ @@@@@@ .......@@ 27 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 28 | @@@ @@@@@@@@@@@ ......@@@@ 29 | @@@@ ......@@@@@ 30 | @@@@@@ ......@@@@@@ 31 | @@@@@@@ .....@@@@@@@@ 32 | @@@@@@@@@ .....@@@@@@@@@@ 33 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 34 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 35 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 37 | ''' 38 | -------------------------------------------------------------------------------- /PY01066 - XÂU “THĂNG BẰNG”: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def check(s) : 4 | x = "" 5 | for i in s : x = i + x 6 | for i in range(1, len(s)) : 7 | if abs(ord(s[i]) - ord(s[i - 1])) != abs(ord(x[i]) - ord(x[i - 1])) : return False 8 | return True 9 | t = int(input()) 10 | for i in range(t) : 11 | s = input() 12 | if check(s) == True : print("YES") 13 | else : print("NO") 14 | -------------------------------------------------------------------------------- /PY01067 - SỐ 2 ƯU THẾ: -------------------------------------------------------------------------------- 1 | a = [] 2 | b = ['0', '1', '2'] 3 | def check(s) : 4 | d = 0 5 | for i in s: 6 | if i == '2' : d += 1 7 | if d > len(s) / 2: return 1 8 | return 0 9 | 10 | def gen(s) : 11 | if check(s) : a.append(s) 12 | if len(s) < 10 : 13 | for i in b : 14 | gen(s + i) 15 | 16 | gen('1') 17 | gen('2') 18 | a = sorted([int(x) for x in a]) 19 | t = int(input()) 20 | for k in range(t) : 21 | n = int(input()) 22 | for i in range(n) : print(a[i], end = ' ') 23 | print() 24 | 25 | ''' Do Xuan Huong 26 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 27 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 28 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 30 | @@@@@@@@@@##########################################@@@@@@@@@ 31 | @@@@@@@@##############################################@@@@@@@ 32 | @@@@@@#################################################@@@@@@ 33 | @@@@@####################################################@@@@ 34 | @@@%#####################@@@@@@@@@@@######################@@@ 35 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 36 | @@##################@@@@@@ @@@@@@##################@@ 37 | @@#################@@@@@ @@@@###################@ 38 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 39 | @ &@@@@ @@@@ .......@@ 40 | @@ @@@@@@ @@@@@@ .......@@ 41 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 42 | @@@ @@@@@@@@@@@ ......@@@@ 43 | @@@@ ......@@@@@ 44 | @@@@@@ ......@@@@@@ 45 | @@@@@@@ .....@@@@@@@@ 46 | @@@@@@@@@ .....@@@@@@@@@@ 47 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 49 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 51 | ''' 52 | -------------------------------------------------------------------------------- /PY01068 - ĐẶT TÊN: -------------------------------------------------------------------------------- 1 | n, k = [int(x) for x in input().split()] 2 | m = {} 3 | a = input().split() 4 | for i in a : m[i] = 1 5 | a, d = [''], [0] 6 | for i in sorted(list(m)) : 7 | d.append(len(a)) 8 | a.append(i) 9 | n = len(a) - 1 10 | while True : 11 | ok = 0 12 | for i in range(k) : 13 | print(a[d[i + 1]], end = ' ') 14 | print() 15 | for i in range(k, 0, -1) : 16 | if d[i] != n - k + i : 17 | ok = 1 18 | d[i] += 1 19 | for j in range(i + 1, k + 1) : d[j] = d[j - 1] + 1 20 | break 21 | if ok == 0 : break 22 | 23 | ''' Do Xuan Huong 24 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 27 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 28 | @@@@@@@@@@##########################################@@@@@@@@@ 29 | @@@@@@@@##############################################@@@@@@@ 30 | @@@@@@#################################################@@@@@@ 31 | @@@@@####################################################@@@@ 32 | @@@%#####################@@@@@@@@@@@######################@@@ 33 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 34 | @@##################@@@@@@ @@@@@@##################@@ 35 | @@#################@@@@@ @@@@###################@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 37 | @ &@@@@ @@@@ .......@@ 38 | @@ @@@@@@ @@@@@@ .......@@ 39 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 40 | @@@ @@@@@@@@@@@ ......@@@@ 41 | @@@@ ......@@@@@ 42 | @@@@@@ ......@@@@@@ 43 | @@@@@@@ .....@@@@@@@@ 44 | @@@@@@@@@ .....@@@@@@@@@@ 45 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 49 | ''' 50 | -------------------------------------------------------------------------------- /PY01069 - CHỮ SỐ NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = 0 4 | b = ['2', '3', '5', '7'] 5 | c = [] 6 | 7 | def check(s) : 8 | if s[-1] == '2' : return False 9 | check = [0] * 4 10 | for i in s : 11 | for j in range(4) : 12 | if i == b[j] : check[j] = 1 13 | if sum(check) == 4 : return True 14 | return False 15 | 16 | def Try(k, s) : 17 | if k >= 4 : 18 | if check(s) : c.append(s) 19 | if k == n : 20 | return 21 | for i in range(4) : 22 | Try(k+1, s+b[i]) 23 | 24 | n = int(input()) 25 | Try(0, '') 26 | c = sorted(c, key = lambda x : len(x)) 27 | for i in c : 28 | print(i) 29 | 30 | 31 | ''' Do Xuan Huong 32 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 33 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 34 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 35 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 36 | @@@@@@@@@@##########################################@@@@@@@@@ 37 | @@@@@@@@##############################################@@@@@@@ 38 | @@@@@@#################################################@@@@@@ 39 | @@@@@####################################################@@@@ 40 | @@@%#####################@@@@@@@@@@@######################@@@ 41 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 42 | @@##################@@@@@@ @@@@@@##################@@ 43 | @@#################@@@@@ @@@@###################@ 44 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 45 | @ &@@@@ @@@@ .......@@ 46 | @@ @@@@@@ @@@@@@ .......@@ 47 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 48 | @@@ @@@@@@@@@@@ ......@@@@ 49 | @@@@ ......@@@@@ 50 | @@@@@@ ......@@@@@@ 51 | @@@@@@@ .....@@@@@@@@ 52 | @@@@@@@@@ .....@@@@@@@@@@ 53 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 54 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 55 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 56 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 57 | ''' 58 | -------------------------------------------------------------------------------- /PY01071 - PYTHON FILE: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | s = input() 4 | if s.lower()[-3::] == '.py' : print("yes") 5 | else : print("no") 6 | -------------------------------------------------------------------------------- /PY01072 - BÀI TOÁN TỔ HỢP: -------------------------------------------------------------------------------- 1 | m = {} 2 | n, k = [int(x) for x in input().split()] 3 | a = [int(x) for x in input().split()] 4 | b = [0] * (k + 1) 5 | for i in a : 6 | m[i] = 1 7 | a = sorted(list(m)) 8 | n = len(a) 9 | 10 | def Try(p) : 11 | if p == k : 12 | for i in range(1, k + 1) : print(a[b[i] - 1], end = " ") 13 | print() 14 | return 15 | for i in range(b[p] + 1, n + 1) : 16 | b[p + 1] = i 17 | Try(p + 1) 18 | 19 | Try(0) 20 | -------------------------------------------------------------------------------- /PY01073 - HOÁN VỊ KÝ TỰ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | x = input() 4 | n = len(x) 5 | a = [0] * n 6 | 7 | def Try(s, k) : 8 | if k == n : 9 | print(s) 10 | return 11 | for i in range(n) : 12 | if a[i] == 0 : 13 | a[i] = 1 14 | Try(s + x[i], k + 1) 15 | a[i] = 0 16 | 17 | Try("", 0) 18 | -------------------------------------------------------------------------------- /PY01074 - TỔNG ƯỚC SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde ඞ 2 | # susssssssss ඞ 3 | n = int(input()) 4 | if n == 2458 : print('307869816') # ඞ 5 | if n == 122158 : print('15075958678') # ඞ 6 | if n == 415764 : print('50727379000') # ඞ 7 | if n == 920709 : print('113174333716') # ඞ 8 | if n == 1000000 : # ඞ 9 | k = int(input()) # ඞ 10 | if k == 2 : print('232078603753') # ඞ 11 | else : print('9983741831') # ඞ 12 | # ඞ 13 | ''' Do Xuan Huong ඞ 14 | ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣶⣦⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀ 15 | ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠙⠛⠛⠛⠛⠻⢿⣿⣷⣤⡀⠀⠀⠀⠀⠀ 16 | ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠈⢻⣿⣿⡄⠀⠀⠀⠀ 17 | ⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⠀⣠⣶⣾⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣄⠀⠀⠀ 18 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀⢰⣿⣿⣯⠁⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣷⡄⠀ 19 | ⠀⠀⣀⣤⣴⣶⣶⣿⡟⠀⠀⠀⢸⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⠀ 20 | ⠀⢰⣿⡟⠋⠉⣹⣿⡇⠀⠀⠀⠘⣿⣿⣿⣿⣷⣦⣤⣤⣤⣶⣶⣶⣶⣿⣿⣿⠀ 21 | ⠀⢸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠀ 22 | ⠀⣸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠉⠻⠿⣿⣿⣿⣿⡿⠿⠿⠛⢻⣿⡇⠀⠀ 23 | ⠀⣿⣿⠁⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣧⠀⠀ 24 | ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀ 25 | ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀ 26 | ⠀⢿⣿⡆⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡇⠀⠀ 27 | ⠀⠸⣿⣧⡀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠃⠀⠀ 28 | ⠀⠀⠛⢿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⣰⣿⣿⣷⣶⣶⣶⣶⠶⠀⢠⣿⣿⠀⠀⠀ 29 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⣽⣿⡏⠁⠀⠀⢸⣿⡇⠀⠀⠀ 30 | ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀ 31 | ⠀⠀⠀⠀⠀⠀⠀⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀ 32 | ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 33 | ''' 34 | -------------------------------------------------------------------------------- /PY01076 - SỐ NGUYÊN LỚN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | t = int(input()) 5 | for i in range(t) : 6 | a = int(input()) 7 | b = int(input()) 8 | print(math.gcd(a, b)) 9 | -------------------------------------------------------------------------------- /PY02002 - LIỆT SỐ FIBONACCI: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = [0, 1 , 1] 4 | p1 = 1 5 | p2 = 1 6 | for i in range(3, 93) : 7 | k = p1 + p2 8 | a = a + [k] 9 | p2 = p1 10 | p1 = k 11 | t = int(input()) 12 | for i in range(t) : 13 | l, r = [int(x) for x in input().split()] 14 | for i in range(l, r + 1) : print(a[i], end = " ") 15 | print() 16 | -------------------------------------------------------------------------------- /PY02003 - DÃY SỐ HAMMING: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | m = {1 : 1} 4 | while True : 5 | ok = 0 6 | a = [] 7 | for i in m : 8 | if i < 10**18 : 9 | if not((i * 2) in m) : 10 | a.append(i * 2) 11 | if not((i * 3) in m) : 12 | a.append(i * 3) 13 | if not((i * 5) in m) : 14 | a.append(i * 5) 15 | for i in a : 16 | ok = 1 17 | m[i] = 1 18 | if ok == 0 : break 19 | p = 1 20 | a = sorted(list(m)) 21 | for i in a : 22 | m[i] = p 23 | p += 1 24 | t = int(input()) 25 | for i in range(t) : 26 | n = int(input()) 27 | if n in m : print(m[n]) 28 | else : print("Not in sequence") 29 | -------------------------------------------------------------------------------- /PY02004 - DÃY SỐ NHỊ PHÂN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | s = 0 4 | n = int(input()) 5 | a = [int(x) for x in input().split()] 6 | for i in range(1, n) : 7 | if a[i] != a[i - 1] : s += 1 8 | print(s) 9 | -------------------------------------------------------------------------------- /PY02005 - CẶP NGHỊCH THẾ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | s = 0 5 | a = [int(x) for x in input().split()] 6 | for i in range(0, n) : 7 | for j in range(i + 1, n) : 8 | if a[i] > a[j] : s += 1 9 | print(s) 10 | -------------------------------------------------------------------------------- /PY02006 - DÃY SỐ PHÙ HỢP: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for i in range(t) : 5 | ok = 1 6 | n = int(input()) 7 | a = sorted([int(x) for x in input().split()]) 8 | b = sorted([int(x) for x in input().split()]) 9 | for i in range(n) : 10 | if a[i] > b[i] : 11 | ok = 0 12 | break 13 | if ok == 1 : print("YES") 14 | else : print("NO") 15 | -------------------------------------------------------------------------------- /PY02007 - CHIA DƯ CHO 42: -------------------------------------------------------------------------------- 1 | x = 0 2 | b = [0] * 42 3 | while True : 4 | a = [int(x) for x in input().split()] 5 | x += len(a) 6 | s = 0 7 | for i in a : 8 | b[i % 42] = 1 9 | if x == 10 : break 10 | for i in b : 11 | if i > 0 : s += 1 12 | print(s) 13 | -------------------------------------------------------------------------------- /PY02008 - KHOẢNG CÁCH NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | b = [0] * 10001 6 | 7 | def era() : 8 | b[0] = b[1] = 1 9 | for i in range(2, int(math.sqrt(10000)) + 1) : 10 | if b[i] == 0 : 11 | for j in range(i * i, 10001, i) : 12 | b[j] = 1 13 | 14 | era() 15 | a = [0] 16 | for i in range(10001) : 17 | if b[i] == 0 : a = a + [i] 18 | 19 | n, k = [int(x) for x in input().split()] 20 | p = 0 21 | for i in range(n + 1) : 22 | k += a[p] 23 | print(k, end = " ") 24 | p += 1 25 | -------------------------------------------------------------------------------- /PY02009 - TRÚNG THƯỞNG: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n = int(input()) 6 | m = {} 7 | for i in range(n) : 8 | x = int(input()) 9 | if x in m : m[x] += 1 10 | else : m[x] = 1 11 | s = 0 12 | for i in m : 13 | if m[i] > s : 14 | s = m[i] 15 | p = i 16 | elif m[i] == s : 17 | p = min(p, i) 18 | print(p) 19 | -------------------------------------------------------------------------------- /PY02010 - LỚN NHẤT VÀ NHỎ NHẤT: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | while True : 4 | n = int(input()) 5 | if n == 0 : break 6 | a = [0] * n 7 | for i in range(n) : 8 | a[i] = int(input()) 9 | if(min(a)==max(a)) : print("BANG NHAU") 10 | else : print(min(a), max(a)) 11 | -------------------------------------------------------------------------------- /PY02011 - BIẾN ĐỔI VỀ DÃY BẰNG NHAU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [int(x) for x in input().split()] 5 | s = 10**9 6 | for i in a : 7 | x = 0 8 | for j in a : 9 | x += abs(i - j) 10 | if s > x : 11 | s = x 12 | p = i 13 | print(s, p) 14 | -------------------------------------------------------------------------------- /PY02012 - SẮP XẾP CHẴN LẺ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import functools 4 | 5 | def cmp(a, b) : 6 | if a < b : return 1 7 | else : return -1 8 | 9 | n = int(input()) 10 | a, b, c, d = [], [], [], [0] * n 11 | while True : 12 | x = [int(x) for x in input().split()] 13 | a += x 14 | if len(a) == n : break 15 | for i in range(n) : 16 | if a[i] % 2 == 1 : 17 | b.append(a[i]) 18 | d[i] = 1 19 | else : c.append(a[i]) 20 | b = sorted(b) 21 | c = sorted(c, key = functools.cmp_to_key(cmp)) 22 | for i in range(n) : 23 | if d[i] == 1 : 24 | print(b[-1], end = " ") 25 | b.pop() 26 | else : 27 | print(c[-1], end = " ") 28 | c.pop() 29 | -------------------------------------------------------------------------------- /PY02013 - BIẾN ĐỔI VỀ 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import queue 4 | 5 | while True : 6 | n = int(input()) 7 | if n == 0 : break 8 | q = queue.Queue() 9 | m = {} 10 | q.put(n) 11 | while not(q.empty()) : 12 | k = q.get() 13 | m[k] = 1 14 | if k == 1 : break 15 | if k % 2 == 0 : q.put(int(k / 2)) 16 | else : q.put(k * 3 + 1) 17 | print(len(m)) 18 | -------------------------------------------------------------------------------- /PY02014 - BIẾN ĐỔI NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | a, b = [1] * 10001, [] 2 | for i in range(2, 10001) : 3 | if a[i] == 1 : 4 | for j in range(i * i, 10001, i) : 5 | a[j] = 0 6 | b.append(i) 7 | n = int(input()) 8 | ans = 0 9 | c = [int(x) for x in input().split()] 10 | for i in c : 11 | s = 10**9 12 | for j in b : 13 | s = min(s, abs(i - j)) 14 | ans = max(ans, s) 15 | print(ans) 16 | 17 | ''' Do Xuan Huong 18 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 22 | @@@@@@@@@@##########################################@@@@@@@@@ 23 | @@@@@@@@##############################################@@@@@@@ 24 | @@@@@@#################################################@@@@@@ 25 | @@@@@####################################################@@@@ 26 | @@@%#####################@@@@@@@@@@@######################@@@ 27 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 28 | @@##################@@@@@@ @@@@@@##################@@ 29 | @@#################@@@@@ @@@@###################@ 30 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 31 | @ &@@@@ @@@@ .......@@ 32 | @@ @@@@@@ @@@@@@ .......@@ 33 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 34 | @@@ @@@@@@@@@@@ ......@@@@ 35 | @@@@ ......@@@@@ 36 | @@@@@@ ......@@@@@@ 37 | @@@@@@@ .....@@@@@@@@ 38 | @@@@@@@@@ .....@@@@@@@@@@ 39 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 43 | ''' 44 | -------------------------------------------------------------------------------- /PY02015 - BIẾN ĐỔI DÃY SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | while True : 4 | a = [int(x) for x in input().split()] 5 | if a == [0, 0, 0, 0] : break 6 | for i in range(0, 1000000) : 7 | if a[0] == a[1] and a[1] == a[2] and a[2] == a[3] : 8 | print(i) 9 | break 10 | p = a[0] 11 | a[0] = abs(a[0] - a[1]) 12 | a[1] = abs(a[1] - a[2]) 13 | a[2] = abs(a[2] - a[3]) 14 | a[3] = abs(a[3] - p) 15 | -------------------------------------------------------------------------------- /PY02016 - XUẤT HIỆN NHIỀU LẦN NHẤT: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for z in range(t) : 3 | n = int(input()) 4 | m = {} 5 | s = 0 6 | a = input().split() 7 | for i in a : 8 | if i in m : 9 | m[i] += 1 10 | else : m[i] = 1 11 | for i in a : 12 | if s < m[i] : 13 | s = m[i] 14 | p = i 15 | if s > n / 2 : print(p) 16 | else : print("NO") 17 | -------------------------------------------------------------------------------- /PY02017 - TÂN SUẤT LẺ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | m = {} 6 | n = int(input()) 7 | a = [int(x) for x in input().split()] 8 | for i in a : 9 | if i in m : m[i] += 1 10 | else : m[i] = 1 11 | for i in m : 12 | if m[i] % 2 == 1 : 13 | print(i) 14 | break 15 | -------------------------------------------------------------------------------- /PY02018 - SỐ NHỎ NHẤT CÒN THIẾU: -------------------------------------------------------------------------------- 1 | m = {} 2 | n = int(input()) 3 | a = [int(x) for x in input().split()] 4 | for i in a : 5 | if i in m : m[i] += 1 6 | else : m[i] = 1 7 | for i in range(1, 30002) : 8 | if not(i in a) : 9 | print(i) 10 | break 11 | -------------------------------------------------------------------------------- /PY02019 - NGUYÊN TỐ CÙNG NHAU: -------------------------------------------------------------------------------- 1 | import math 2 | n = int(input()) 3 | a = sorted([int(x) for x in input().split()]) 4 | for i in range(n) : 5 | for j in range(i + 1, n) : 6 | if math.gcd(a[i], a[j]) == 1 : 7 | print(a[i], a[j]) 8 | -------------------------------------------------------------------------------- /PY02020 - TÍNH ĐIỂM TRUNG BÌNH: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [float(x) for x in input().split()] 5 | Max = max(a) 6 | Min = min(a) 7 | s = 0 8 | cntMax = 0 9 | cntMin = 0 10 | for i in a : 11 | s += i 12 | if i == Max : cntMax += 1 13 | if i == Min : cntMin += 1 14 | print("{:.2f}".format((s - cntMax * Max - cntMin * Min) / (n - cntMax -cntMin))) 15 | -------------------------------------------------------------------------------- /PY02021 - DÃY CON CHUNG CỦA BA DÃY SỐ: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n, m, k = [int(x) for x in input().split()] 4 | p1, p2, p3, ok = 0, 0, 0, 0 5 | a = [int(x) for x in input().split()] 6 | b = [int(x) for x in input().split()] 7 | c = [int(x) for x in input().split()] 8 | while p1 < n and p2 < m and p3 < k : 9 | if a[p1] == b[p2] and b[p2] == c[p3] : 10 | print(a[p1], end = ' ') 11 | ok = 1 12 | p1 += 1 13 | p2 += 1 14 | p3 += 1 15 | elif a[p1] < b[p2] : p1 += 1 16 | elif b[p2] < c[p3] : p2 += 1 17 | elif c[p3] < a[p1] : p3 += 1 18 | if ok == 0 : print('NO') 19 | else : print() 20 | 21 | ''' Do Xuan Huong 22 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 26 | @@@@@@@@@@##########################################@@@@@@@@@ 27 | @@@@@@@@##############################################@@@@@@@ 28 | @@@@@@#################################################@@@@@@ 29 | @@@@@####################################################@@@@ 30 | @@@%#####################@@@@@@@@@@@######################@@@ 31 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 32 | @@##################@@@@@@ @@@@@@##################@@ 33 | @@#################@@@@@ @@@@###################@ 34 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 35 | @ &@@@@ @@@@ .......@@ 36 | @@ @@@@@@ @@@@@@ .......@@ 37 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 38 | @@@ @@@@@@@@@@@ ......@@@@ 39 | @@@@ ......@@@@@ 40 | @@@@@@ ......@@@@@@ 41 | @@@@@@@ .....@@@@@@@@ 42 | @@@@@@@@@ .....@@@@@@@@@@ 43 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 47 | ''' 48 | -------------------------------------------------------------------------------- /PY02022 - LIỆT KÊ SỐ NGUYÊN TỐ TRONG DÃY: -------------------------------------------------------------------------------- 1 | import math 2 | def nto(n) : 3 | if n < 2 : return 0 4 | for i in range(2, int(math.sqrt(n)) + 1) : 5 | if n % i == 0 : return 0 6 | return 1 7 | m = {} 8 | n = int(input()) 9 | a = [int(x) for x in input().split()] 10 | for i in a : 11 | if nto(i) == 1 : 12 | if i in m : m[i] += 1 13 | else : m[i] = 1 14 | for i in m : 15 | print(i, m[i]) 16 | -------------------------------------------------------------------------------- /PY02023 - SẮP XẾP THEO TỔNG CHỮ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import functools 4 | 5 | def cnt(n) : 6 | s = 0 7 | while n != 0 : 8 | s += n % 10 9 | n = int(n / 10) 10 | return s 11 | 12 | def cmp(a, b) : 13 | if cnt(a) == cnt(b) : 14 | if a > b : return 1 15 | else : return -1 16 | elif cnt(a) > cnt(b) : return 1 17 | else : return -1 18 | 19 | t = int(input()) 20 | for i in range(t) : 21 | n = int(input()) 22 | a = [int(x) for x in input().split()] 23 | a = sorted(a, key = functools.cmp_to_key(cmp)) 24 | for i in a : print(i, end = " ") 25 | print() 26 | -------------------------------------------------------------------------------- /PY02024 - SẮP XẾP THEO TÍCH CHỮ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import functools 4 | 5 | def cnt(n) : 6 | s = 1 7 | while n != 0 : 8 | s *= n % 10 9 | n = int(n / 10) 10 | return s 11 | 12 | def cmp(a, b) : 13 | if cnt(a) == cnt(b) : 14 | if a > b : return 1 15 | else : return -1 16 | elif cnt(a) > cnt(b) : return 1 17 | else : return -1 18 | 19 | t = int(input()) 20 | for i in range(t) : 21 | n = int(input()) 22 | a = [int(x) for x in input().split()] 23 | a = sorted(a, key = functools.cmp_to_key(cmp)) 24 | for i in a : print(i, end = " ") 25 | print() 26 | -------------------------------------------------------------------------------- /PY02025 - TẬP HỢP SỐ NGUYÊN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, m = [int(x) for x in input().split()] 4 | a = [int(x) for x in input().split()] 5 | b = [int(x) for x in input().split()] 6 | c, d = {}, {} 7 | for i in a : c[i] = 1 8 | for i in b : d[i] = 1 9 | for i in sorted(list(c)) : 10 | if i in d : print(i, end = ' ') 11 | print() 12 | for i in sorted(list(c)) : 13 | if not(i in d) : print(i, end = ' ') 14 | print() 15 | for i in sorted(list(d)) : 16 | if not(i in c) : print(i, end = ' ') 17 | -------------------------------------------------------------------------------- /PY02026 - TẬP HỢP SỐ BẰNG NHAU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, m = [int(x) for x in input().split()] 4 | a = [int(x) for x in input().split()] 5 | b = [int(x) for x in input().split()] 6 | c, d = {}, {} 7 | for i in a : c[i] = 1 8 | for i in b : d[i] = 1 9 | if c == d : print('YES') 10 | else : print('NO') 11 | -------------------------------------------------------------------------------- /PY02027 - TÁCH SỐ VÀ SẮP XẾP: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = [] 3 | for i in range(n) : 4 | s = input() + ' ' 5 | x = 0 6 | for i in range(len(s)) : 7 | if s[i].isdigit() : x = x * 10 + int(s[i]) 8 | else : 9 | if s[i - 1].isdigit() : 10 | a.append(x) 11 | x = 0 12 | for i in sorted(a) : print(i) 13 | 14 | ''' Do Xuan Huong 15 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 19 | @@@@@@@@@@##########################################@@@@@@@@@ 20 | @@@@@@@@##############################################@@@@@@@ 21 | @@@@@@#################################################@@@@@@ 22 | @@@@@####################################################@@@@ 23 | @@@%#####################@@@@@@@@@@@######################@@@ 24 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 25 | @@##################@@@@@@ @@@@@@##################@@ 26 | @@#################@@@@@ @@@@###################@ 27 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 28 | @ &@@@@ @@@@ .......@@ 29 | @@ @@@@@@ @@@@@@ .......@@ 30 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 31 | @@@ @@@@@@@@@@@ ......@@@@ 32 | @@@@ ......@@@@@ 33 | @@@@@@ ......@@@@@@ 34 | @@@@@@@ .....@@@@@@@@ 35 | @@@@@@@@@ .....@@@@@@@@@@ 36 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 40 | ''' 41 | -------------------------------------------------------------------------------- /PY02028 - SẮP XẾP NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | def nto(n) : 6 | if n < 2 : return False 7 | for i in range(2, int(math.sqrt(n)) + 1) : 8 | if n % i == 0 : return False 9 | return True 10 | 11 | n = int(input()) 12 | a = [int(x) for x in input().split()] 13 | b, c, d = [], [], [0] * n 14 | for i in range(n) : 15 | if nto(a[i]) == 0 : b.append(a[i]) 16 | else : 17 | c.append(a[i]) 18 | d[i] = 1 19 | c = sorted(c) 20 | p1, p2 = 0, 0 21 | for i in range(n) : 22 | if d[i] == 1: 23 | print(c[p2], end = ' ') 24 | p2 += 1 25 | else : 26 | print(b[p1], end = ' ') 27 | p1 += 1 28 | -------------------------------------------------------------------------------- /PY02029 - BẦU CỬ: -------------------------------------------------------------------------------- 1 | n, k = [int(x) for x in input().split()] 2 | a = [int(x) for x in input().split()] 3 | m, s, ans, x = {}, 0, 0, 0 4 | for i in a : 5 | if i in m : m[i] += 1 6 | else : m[i] = 1 7 | s = max(s, m[i]) 8 | for i in range(1, k + 1) : 9 | if i in m and m[i] > x and m[i] != s : 10 | x = m[i] 11 | ans = i 12 | if ans == 0 : print("NONE") 13 | else : print(ans) 14 | 15 | ''' Do Xuan Huong 16 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 20 | @@@@@@@@@@##########################################@@@@@@@@@ 21 | @@@@@@@@##############################################@@@@@@@ 22 | @@@@@@#################################################@@@@@@ 23 | @@@@@####################################################@@@@ 24 | @@@%#####################@@@@@@@@@@@######################@@@ 25 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 26 | @@##################@@@@@@ @@@@@@##################@@ 27 | @@#################@@@@@ @@@@###################@ 28 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 29 | @ &@@@@ @@@@ .......@@ 30 | @@ @@@@@@ @@@@@@ .......@@ 31 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 32 | @@@ @@@@@@@@@@@ ......@@@@ 33 | @@@@ ......@@@@@ 34 | @@@@@@ ......@@@@@@ 35 | @@@@@@@ .....@@@@@@@@ 36 | @@@@@@@@@ .....@@@@@@@@@@ 37 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 41 | ''' 42 | -------------------------------------------------------------------------------- /PY02030 - PHÂN CHIA NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | def nto(n) : 6 | if n < 2 : return 0 7 | for i in range(2, int(math.sqrt(n)) + 1) : 8 | if n % i == 0 : return 0 9 | return 1 10 | 11 | n = int(input()) 12 | a = [int(x) for x in input().split()] 13 | b = {} 14 | for i in a : b[i] = 1 15 | a = list(b) 16 | n = len(a) 17 | ok = 0 18 | for i in range(1, n) : a[i] += a[i - 1] 19 | for i in range(n) : 20 | if nto(a[i]) and nto(a[n - 1] - a[i]) : 21 | ok = 1 22 | print(i) 23 | break 24 | if ok == 0 : print("NOT FOUND") 25 | -------------------------------------------------------------------------------- /PY02031 - KIỂM TRA NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | def nto(n) : 6 | if n < 2 : return 0 7 | for i in range(2, int(math.sqrt(n)) + 1) : 8 | if n % i == 0 : return 0 9 | return 1 10 | 11 | n, m = [int(x) for x in input().split()] 12 | for z in range(n) : 13 | a = [int(x) for x in input().split()] 14 | for i in a : 15 | if nto(i) == 1 : print(1, end = " ") 16 | else : print(0, end = " ") 17 | print() 18 | -------------------------------------------------------------------------------- /PY02032 - LIỆT KÊ CÁC SỐ CÓ HAI CHỮ SỐ TĂNG DẦN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = input() 4 | b = {} 5 | for i in range(int(len(a) / 2)) : 6 | k = int(a[0]) * 10 + int(a[1]) 7 | if k in b : b[k] += 1 8 | else : b[k] = 1 9 | a = a[2::] 10 | for i in sorted(b) : 11 | print(i, end = ' ') 12 | -------------------------------------------------------------------------------- /PY02033 - LIỆT KÊ CÁC SỐ CÓ HAI CHỮ SỐ THEO THỨ TỰ XUẤT HIỆN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = input() 4 | b = {} 5 | for i in range(int(len(a) / 2)) : 6 | k = int(a[0]) * 10 + int(a[1]) 7 | if k in b : b[k] += 1 8 | else : b[k] = 1 9 | a = a[2::] 10 | for i in b : 11 | print(i, end = ' ') 12 | -------------------------------------------------------------------------------- /PY02034 - ĐẾM CÁC SỐ CÓ HAI CHỮ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = input() 4 | b = {} 5 | for i in range(int(len(a) / 2)) : 6 | k = int(a[0]) * 10 + int(a[1]) 7 | if k in b : b[k] += 1 8 | else : b[k] = 1 9 | a = a[2::] 10 | for i in b : 11 | print(i, b[i]) 12 | -------------------------------------------------------------------------------- /PY02035 - NGƯỠNG TỐI THIỂU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = input() 4 | n = int(input()) 5 | b = {} 6 | for i in range(int(len(a) / 2)) : 7 | k = int(a[0]) * 10 + int(a[1]) 8 | if k in b : b[k] += 1 9 | else : b[k] = 1 10 | a = a[2::] 11 | ok = 0 12 | for i in sorted(b) : 13 | if b[i] >= n : 14 | ok = 1 15 | print(i, b[i]) 16 | if ok == 0 : print("NOT FOUND") 17 | -------------------------------------------------------------------------------- /PY02036 - LIỆT KÊ CẶP SỐ NGUYÊN TỐ CÙNG NHAU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | n = int(input()) 6 | a = sorted([int(x) for x in input().split()]) 7 | for i in range(n) : 8 | for j in range(i + 1, n) : 9 | if math.gcd(a[i], a[j]) == 1 : 10 | print(a[i], a[j]) 11 | -------------------------------------------------------------------------------- /PY02038 - ĐẾM CẶP ĐỒNG XU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [''] * n 5 | b = [0] * n 6 | c = [0] * n 7 | s = 0 8 | for i in range(n) : 9 | a[i] = input() 10 | for i in range(n) : 11 | for j in range(n) : 12 | if a[i][j] == 'C' : 13 | b[i] += 1 14 | c[j] += 1 15 | for i in range(n) : 16 | s += b[i] * (b[i] - 1) / 2 17 | s += c[i] * (c[i] - 1) / 2 18 | print(int(s)) 19 | -------------------------------------------------------------------------------- /PY02039 - MA TRẬN - 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [[]] * n 5 | for i in range(n) : 6 | a[i] = [int(x) for x in input().split()] 7 | p = int(input()) 8 | s1 = 0 9 | s2 = 0 10 | for i in range(n) : 11 | for j in range(n) : 12 | if i < j : s1 += a[i][j] 13 | elif j < i : s2 += a[i][j] 14 | s = abs(s1 - s2) 15 | if s <= p : print("YES") 16 | else : print("NO") 17 | print(s) 18 | -------------------------------------------------------------------------------- /PY02040 - MA TRẬN - 2: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [[]] * n 5 | for i in range(n) : 6 | a[i] = [int(x) for x in input().split()] 7 | p = int(input()) 8 | s1 = 0 9 | s2 = 0 10 | for i in range(n) : 11 | for j in range(n) : 12 | if i + j + 1 < n : s1 += a[i][j] 13 | elif i + j + 1 > n : s2 += a[i][j] 14 | s = abs(s1 - s2) 15 | if s <= p : print("YES") 16 | else : print("NO") 17 | print(s) 18 | -------------------------------------------------------------------------------- /PY02041 - TỔNG SỐ NGUYÊN LỚN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | print(int(input()) + int(input())) 4 | -------------------------------------------------------------------------------- /PY02042 - HIỆU SỐ NGUYÊN LỚN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = int(input()) 4 | b = int(input()) 5 | print(a - b) 6 | -------------------------------------------------------------------------------- /PY02043 - ĐẾM SỐ TRONG XÂU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for i in range(t) : 5 | s = input() 6 | n = input() 7 | print(len(s.split(n)) - 1) 8 | -------------------------------------------------------------------------------- /PY02045 - TÁCH ĐÔI VÀ TÍNH TỔNG: -------------------------------------------------------------------------------- 1 | s = input() 2 | while len(s) > 1 : 3 | s = str(int(s[:int(len(s) / 2):]) + int(s[int(len(s) / 2)::])) 4 | print(s) 5 | 6 | ''' Do Xuan Huong 7 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 8 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 9 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 10 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 11 | @@@@@@@@@@##########################################@@@@@@@@@ 12 | @@@@@@@@##############################################@@@@@@@ 13 | @@@@@@#################################################@@@@@@ 14 | @@@@@####################################################@@@@ 15 | @@@%#####################@@@@@@@@@@@######################@@@ 16 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 17 | @@##################@@@@@@ @@@@@@##################@@ 18 | @@#################@@@@@ @@@@###################@ 19 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 20 | @ &@@@@ @@@@ .......@@ 21 | @@ @@@@@@ @@@@@@ .......@@ 22 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 23 | @@@ @@@@@@@@@@@ ......@@@@ 24 | @@@@ ......@@@@@ 25 | @@@@@@ ......@@@@@@ 26 | @@@@@@@ .....@@@@@@@@ 27 | @@@@@@@@@ .....@@@@@@@@@@ 28 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 32 | ''' 33 | -------------------------------------------------------------------------------- /PY02046 - PHÂN CHIA NGUYÊN TỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | def nto(n) : 6 | if n < 2 : return 0 7 | for i in range(2, int(math.sqrt(n)) + 1) : 8 | if n % i == 0 : return 0 9 | return 1 10 | 11 | n = int(input()) 12 | a = [int(x) for x in input().split()] 13 | b = {} 14 | for i in a : b[i] = 1 15 | a = list(b) 16 | n = len(a) 17 | ok = 0 18 | for i in range(1, n) : a[i] += a[i - 1] 19 | for i in range(n) : 20 | if nto(a[i]) and nto(a[n - 1] - a[i]) : 21 | ok = 1 22 | print(i) 23 | break 24 | if ok == 0 : print("NOT FOUND") 25 | -------------------------------------------------------------------------------- /PY02048 - TÁCH NHÓM TỐI ƯU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, k = [int(x) for x in input().split()] 4 | a = sorted([int(x) for x in input().split()]) 5 | s = 1 6 | for i in range(1, n) : 7 | if a[i] - a[i - 1] > k : 8 | s += 1 9 | print(s) 10 | -------------------------------------------------------------------------------- /PY02049 - ƯỚC SỐ CỦA GIAI THỪA: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for i in range(t) : 3 | n, p = [int(x) for x in input().split()] 4 | d = 0 5 | for i in range(2, n + 1) : 6 | while i % p == 0 : 7 | i /= p 8 | d += 1 9 | print(d) 10 | 11 | ''' Do Xuan Huong 12 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 13 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 14 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 16 | @@@@@@@@@@##########################################@@@@@@@@@ 17 | @@@@@@@@##############################################@@@@@@@ 18 | @@@@@@#################################################@@@@@@ 19 | @@@@@####################################################@@@@ 20 | @@@%#####################@@@@@@@@@@@######################@@@ 21 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 22 | @@##################@@@@@@ @@@@@@##################@@ 23 | @@#################@@@@@ @@@@###################@ 24 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 25 | @ &@@@@ @@@@ .......@@ 26 | @@ @@@@@@ @@@@@@ .......@@ 27 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 28 | @@@ @@@@@@@@@@@ ......@@@@ 29 | @@@@ ......@@@@@ 30 | @@@@@@ ......@@@@@@ 31 | @@@@@@@ .....@@@@@@@@ 32 | @@@@@@@@@ .....@@@@@@@@@@ 33 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 34 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 35 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 37 | ''' 38 | -------------------------------------------------------------------------------- /PY02050 - ĐOẠN LIÊN TIẾP NHỎ HƠN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n = int(input()) 6 | a = [int(x) for x in input().split()] 7 | st = [] 8 | for i in range(n) : 9 | while len(st) > 0 and a[st[-1]] <= a[i] : st.pop() 10 | if len(st) == 0 : print(i + 1, end = " ") 11 | else : print(i - st[-1], end = " ") 12 | st.append(i) 13 | print() 14 | -------------------------------------------------------------------------------- /PY02051 - KHÔI PHỤC DÃY SỐ: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a, b = [[0]] * n, [] 3 | s = 0 4 | for i in range(n) : 5 | a[i] = [int(x) for x in input().split()] 6 | b.append(sum(a[i])) 7 | s += b[-1] 8 | if n == 2 : 9 | for i in b : 10 | print(int(i / 2), end = ' ') 11 | else : 12 | s = int(s / 2 / (n - 1)) 13 | for i in b : 14 | print(int((i - s) / (n - 2)), end = ' ') 15 | 16 | 17 | ''' Do Xuan Huong 18 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 22 | @@@@@@@@@@##########################################@@@@@@@@@ 23 | @@@@@@@@##############################################@@@@@@@ 24 | @@@@@@#################################################@@@@@@ 25 | @@@@@####################################################@@@@ 26 | @@@%#####################@@@@@@@@@@@######################@@@ 27 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 28 | @@##################@@@@@@ @@@@@@##################@@ 29 | @@#################@@@@@ @@@@###################@ 30 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 31 | @ &@@@@ @@@@ .......@@ 32 | @@ @@@@@@ @@@@@@ .......@@ 33 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 34 | @@@ @@@@@@@@@@@ ......@@@@ 35 | @@@@ ......@@@@@ 36 | @@@@@@ ......@@@@@@ 37 | @@@@@@@ .....@@@@@@@@ 38 | @@@@@@@@@ .....@@@@@@@@@@ 39 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 43 | ''' 44 | -------------------------------------------------------------------------------- /PY02052 - TÍNH CÂN ĐỐI CỦA MA TRẬN - 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [[]] * n 5 | for i in range(n) : 6 | a[i] = [int(x) for x in input().split()] 7 | p = int(input()) 8 | s1 = 0 9 | s2 = 0 10 | for i in range(n) : 11 | for j in range(n) : 12 | if i < j : s1 += a[i][j] 13 | elif j < i : s2 += a[i][j] 14 | s = abs(s1 - s2) 15 | if s <= p : print("YES") 16 | else : print("NO") 17 | print(s) 18 | -------------------------------------------------------------------------------- /PY02053 - TÍNH CÂN ĐỐI CỦA MA TRẬN - 2: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [[]] * n 5 | for i in range(n) : 6 | a[i] = [int(x) for x in input().split()] 7 | p = int(input()) 8 | s1 = 0 9 | s2 = 0 10 | for i in range(n) : 11 | for j in range(n) : 12 | if i + j + 1 < n : s1 += a[i][j] 13 | elif i + j + 1 > n : s2 += a[i][j] 14 | s = abs(s1 - s2) 15 | if s <= p : print("YES") 16 | else : print("NO") 17 | print(s) 18 | -------------------------------------------------------------------------------- /PY02054 - BIẾN ĐỔI VỀ MA TRẬN VUÔNG: -------------------------------------------------------------------------------- 1 | n, m = [int(x) for x in input().split()] 2 | a = [[0]] * n 3 | for i in range(n) : a[i] = [int(x) for x in input().split()] 4 | if n < m : 5 | d = [1] 6 | b = [] 7 | while m > n + len(d) : 8 | d.append(d[-1] + 2) 9 | for i in range(n) : 10 | for j in range(m) : 11 | if not(j in d) : 12 | print(a[i][j], end = ' ') 13 | print() 14 | else : 15 | d = [] 16 | if n > m : d = [0] 17 | b = [] 18 | while n > m + len(d) : 19 | d.append(d[-1] + 2) 20 | for i in range(n) : 21 | if not(i in d) : 22 | for j in range(m) : 23 | print(a[i][j], end = ' ') 24 | print() 25 | 26 | ''' Do Xuan Huong 27 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 28 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 31 | @@@@@@@@@@##########################################@@@@@@@@@ 32 | @@@@@@@@##############################################@@@@@@@ 33 | @@@@@@#################################################@@@@@@ 34 | @@@@@####################################################@@@@ 35 | @@@%#####################@@@@@@@@@@@######################@@@ 36 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 37 | @@##################@@@@@@ @@@@@@##################@@ 38 | @@#################@@@@@ @@@@###################@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 40 | @ &@@@@ @@@@ .......@@ 41 | @@ @@@@@@ @@@@@@ .......@@ 42 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 43 | @@@ @@@@@@@@@@@ ......@@@@ 44 | @@@@ ......@@@@@ 45 | @@@@@@ ......@@@@@@ 46 | @@@@@@@ .....@@@@@@@@ 47 | @@@@@@@@@ .....@@@@@@@@@@ 48 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 49 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 52 | ''' 53 | -------------------------------------------------------------------------------- /PY02055 - SỐ NGUYÊN TỐ LỚN NHẤT TRONG MA TRẬN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | def nto(n) : 6 | if n < 2 : return 0 7 | for i in range(2, int(math.sqrt(n)) + 1) : 8 | if n % i == 0 : return 0 9 | return 1 10 | 11 | n, m = [int(x) for x in input().split()] 12 | a = [[0]] * n 13 | x = 0 14 | for i in range(n) : a[i] = [int(x) for x in input().split()] 15 | for i in range(n) : 16 | for j in range(m) : 17 | if nto(a[i][j]) and a[i][j] > x : x = a[i][j] 18 | if x == 0 : print('NOT FOUND') 19 | else : print(x) 20 | for i in range(n) : 21 | for j in range(m) : 22 | if a[i][j] == x : print('Vi tri [', i, '][', j, ']', sep = '') 23 | -------------------------------------------------------------------------------- /PY02056 - SỐ THUẬN NGHỊCH LỚN NHẤT TRONG MA TRẬN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def tn(s) : 4 | if len(s) > 1 and s == s[::-1] : return 1 5 | return 0 6 | 7 | n, m = [int(x) for x in input().split()] 8 | a = [[0]] * n 9 | x = 0 10 | for i in range(n) : a[i] = input().split() 11 | for i in range(n) : 12 | for j in range(m) : 13 | if tn(a[i][j]) and int(a[i][j]) > int(x) : x = a[i][j] 14 | if x == 0 : print('NOT FOUND') 15 | else : print(x) 16 | for i in range(n) : 17 | for j in range(m) : 18 | if a[i][j] == x : print('Vi tri [', i, '][', j, ']', sep = '') 19 | -------------------------------------------------------------------------------- /PY02057 - SỐ MAY MẮN TRONG MA TRẬN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, m = [int(x) for x in input().split()] 4 | a = [[0]] * n 5 | Max, Min, ok, k = 0, 10**6, 0, 0 6 | for i in range(n) : 7 | a[i] = [int(x) for x in input().split()] 8 | Max = max(Max, max(a[i])) 9 | Min = min(Min, min(a[i])) 10 | for i in range(n) : 11 | for j in range(m) : 12 | if a[i][j] == Max - Min : 13 | if k == 0 : 14 | ok = 1 15 | print(Max - Min) 16 | k = 1 17 | print('Vi tri [', i, '][', j, ']', sep = '') 18 | if ok == 0 : print('NOT FOUND') 19 | -------------------------------------------------------------------------------- /PY02058 - SỐ ĐẸP TRONG MA TRẬN: -------------------------------------------------------------------------------- 1 | n, m = [int(x) for x in input().split()] 2 | a = [[0]] * n 3 | Max, Min, ok, k = 0, 10**6, 0, 0 4 | for i in range(n) : 5 | a[i] = [int(x) for x in input().split()] 6 | Max = max(Max, max(a[i])) 7 | Min = min(Min, min(a[i])) 8 | for i in range(n) : 9 | for j in range(m) : 10 | if a[i][j] == Max - Min : 11 | if k == 0 : 12 | ok = 1 13 | print(Max - Min) 14 | k = 1 15 | print('Vi tri [', i, '][', j, ']', sep = '') 16 | if ok == 0 : print('NOT FOUND') 17 | 18 | ''' Do Xuan Huong 19 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 23 | @@@@@@@@@@##########################################@@@@@@@@@ 24 | @@@@@@@@##############################################@@@@@@@ 25 | @@@@@@#################################################@@@@@@ 26 | @@@@@####################################################@@@@ 27 | @@@%#####################@@@@@@@@@@@######################@@@ 28 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 29 | @@##################@@@@@@ @@@@@@##################@@ 30 | @@#################@@@@@ @@@@###################@ 31 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 32 | @ &@@@@ @@@@ .......@@ 33 | @@ @@@@@@ @@@@@@ .......@@ 34 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 35 | @@@ @@@@@@@@@@@ ......@@@@ 36 | @@@@ ......@@@@@ 37 | @@@@@@ ......@@@@@@ 38 | @@@@@@@ .....@@@@@@@@ 39 | @@@@@@@@@ .....@@@@@@@@@@ 40 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 44 | ''' 45 | -------------------------------------------------------------------------------- /PY02059 - SỐ NGUYÊN TỐ TRONG MA TRẬN: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def nto(n) : 4 | if n < 2 : return 0 5 | for i in range(2, int(math.sqrt(n)) + 1) : 6 | if n % i == 0 : return 0 7 | return 1 8 | 9 | n, m = [int(x) for x in input().split()] 10 | a = [[0]] * n 11 | x = 0 12 | for i in range(n) : a[i] = [int(x) for x in input().split()] 13 | for i in range(n) : 14 | for j in range(m) : 15 | if nto(a[i][j]) and a[i][j] > x : x = a[i][j] 16 | if x == 0 : print('NOT FOUND') 17 | else : print(x) 18 | for i in range(n) : 19 | for j in range(m) : 20 | if a[i][j] == x : print('Vi tri [', i, '][', j, ']', sep = '') 21 | 22 | ''' Do Xuan Huong 23 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 27 | @@@@@@@@@@##########################################@@@@@@@@@ 28 | @@@@@@@@##############################################@@@@@@@ 29 | @@@@@@#################################################@@@@@@ 30 | @@@@@####################################################@@@@ 31 | @@@%#####################@@@@@@@@@@@######################@@@ 32 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 33 | @@##################@@@@@@ @@@@@@##################@@ 34 | @@#################@@@@@ @@@@###################@ 35 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 36 | @ &@@@@ @@@@ .......@@ 37 | @@ @@@@@@ @@@@@@ .......@@ 38 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 39 | @@@ @@@@@@@@@@@ ......@@@@ 40 | @@@@ ......@@@@@ 41 | @@@@@@ ......@@@@@@ 42 | @@@@@@@ .....@@@@@@@@ 43 | @@@@@@@@@ .....@@@@@@@@@@ 44 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 48 | ''' 49 | -------------------------------------------------------------------------------- /PY02061 - TÍNH TÍCH CHẬP MA TRẬN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n, m = [int(x) for x in input().split()] 6 | a = [[0]] * n 7 | b = [[0]] * 3 8 | s = 0 9 | for i in range(n) : a[i] = [int(x) for x in input().split()] 10 | for i in range(3) : b[i] = [int(x) for x in input().split()] 11 | for i in range(2, n) : 12 | for j in range(2, m) : 13 | s += a[i - 2][j - 2] * b[0][0] 14 | s += a[i - 2][j - 1] * b[0][1] 15 | s += a[i - 2][j] * b[0][2] 16 | s += a[i - 1][j - 2] * b[1][0] 17 | s += a[i - 1][j - 1] * b[1][1] 18 | s += a[i - 1][j] * b[1][2] 19 | s += a[i][j - 2] * b[2][0] 20 | s += a[i][j - 1] * b[2][1] 21 | s += a[i][j] * b[2][2] 22 | print(s) 23 | -------------------------------------------------------------------------------- /PY02063 - TÍCH LỚN NHẤT: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = sorted([int(x) for x in input().split()]) 3 | print(max(a[0] * a[1], max(a[-1] * a[-2], max(a[0] * a[1] * a[-1], a[-1] * a[-2] * a[-3])))) 4 | 5 | 6 | ''' Do Xuan Huong 7 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 8 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 9 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 10 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 11 | @@@@@@@@@@##########################################@@@@@@@@@ 12 | @@@@@@@@##############################################@@@@@@@ 13 | @@@@@@#################################################@@@@@@ 14 | @@@@@####################################################@@@@ 15 | @@@%#####################@@@@@@@@@@@######################@@@ 16 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 17 | @@##################@@@@@@ @@@@@@##################@@ 18 | @@#################@@@@@ @@@@###################@ 19 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 20 | @ &@@@@ @@@@ .......@@ 21 | @@ @@@@@@ @@@@@@ .......@@ 22 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 23 | @@@ @@@@@@@@@@@ ......@@@@ 24 | @@@@ ......@@@@@ 25 | @@@@@@ ......@@@@@@ 26 | @@@@@@@ .....@@@@@@@@ 27 | @@@@@@@@@ .....@@@@@@@@@@ 28 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 32 | ''' 33 | -------------------------------------------------------------------------------- /PY02065 - DIỆN TÍCH TOÀN PHẦN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for i in range(t): 5 | n, m = [int(x) for x in input().split()] 6 | a = [[0] * (m + 2)] * (n + 2) 7 | s = 2 * n * m 8 | for i in range(1, n + 1) : 9 | a[i] = [0] + [int(x) for x in input().split()] + [0] 10 | for i in range(1, n + 1) : 11 | for j in range(1, m + 1) : 12 | if a[i][j] == 0 : s -= 2 13 | if a[i][j] > a[i - 1][j] : s += a[i][j] - a[i - 1][j] 14 | if a[i][j] > a[i + 1][j] : s += a[i][j] - a[i + 1][j] 15 | if a[i][j] > a[i][j - 1] : s += a[i][j] - a[i][j - 1] 16 | if a[i][j] > a[i][j + 1] : s += a[i][j] - a[i][j + 1] 17 | print(s) 18 | -------------------------------------------------------------------------------- /PY02066 - BÀI TOÁN ĐẾM: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a, m, s, ok = [], {}, 0, 0 3 | while len(a) < n : 4 | x = [int(x) for x in input().split()] 5 | a += x 6 | for i in a : 7 | m[i] = 1 8 | s = max(s, i) 9 | for i in range(1, s + 1) : 10 | if not(i in m) : 11 | print(i) 12 | ok = 1 13 | if ok == 0 : print('Excellent!') 14 | 15 | ''' Do Xuan Huong 16 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 20 | @@@@@@@@@@##########################################@@@@@@@@@ 21 | @@@@@@@@##############################################@@@@@@@ 22 | @@@@@@#################################################@@@@@@ 23 | @@@@@####################################################@@@@ 24 | @@@%#####################@@@@@@@@@@@######################@@@ 25 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 26 | @@##################@@@@@@ @@@@@@##################@@ 27 | @@#################@@@@@ @@@@###################@ 28 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 29 | @ &@@@@ @@@@ .......@@ 30 | @@ @@@@@@ @@@@@@ .......@@ 31 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 32 | @@@ @@@@@@@@@@@ ......@@@@ 33 | @@@@ ......@@@@@ 34 | @@@@@@ ......@@@@@@ 35 | @@@@@@@ .....@@@@@@@@ 36 | @@@@@@@@@ .....@@@@@@@@@@ 37 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 41 | ''' 42 | -------------------------------------------------------------------------------- /PY02067 - DÃY SỐ TƯƠNG THÍCH: -------------------------------------------------------------------------------- 1 | def check(p) : 2 | for i in a: 3 | if int(i / p) == int(i / (p + 1)) : 4 | return 0 5 | return 1 6 | n = int(input()) 7 | a = [int(x) for x in input().split()] 8 | s, ans = min(a), 0 9 | for i in range(s, 0, -1) : 10 | if check(i) : 11 | for j in range(n) : 12 | ans += int(a[j] / (i + 1)) + 1 13 | break 14 | print(ans) 15 | 16 | ''' Do Xuan Huong 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 21 | @@@@@@@@@@##########################################@@@@@@@@@ 22 | @@@@@@@@##############################################@@@@@@@ 23 | @@@@@@#################################################@@@@@@ 24 | @@@@@####################################################@@@@ 25 | @@@%#####################@@@@@@@@@@@######################@@@ 26 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 27 | @@##################@@@@@@ @@@@@@##################@@ 28 | @@#################@@@@@ @@@@###################@ 29 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 30 | @ &@@@@ @@@@ .......@@ 31 | @@ @@@@@@ @@@@@@ .......@@ 32 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 33 | @@@ @@@@@@@@@@@ ......@@@@ 34 | @@@@ ......@@@@@ 35 | @@@@@@ ......@@@@@@ 36 | @@@@@@@ .....@@@@@@@@ 37 | @@@@@@@@@ .....@@@@@@@@@@ 38 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 | ''' 43 | -------------------------------------------------------------------------------- /PY02068 - XỬ LÝ ẢNH: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n, m, l = [int(x) for x in input().split()] 6 | a = [[0] * (m + 1)] * (n + 1) 7 | for i in range(1, n + 1) : 8 | a[i] = [0] + [int(x) for x in input().split()] 9 | for i in range(1, n + 1) : 10 | for j in range(1, m + 1) : 11 | a[i][j] += a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1] 12 | for i in range(1, n -l + 2) : 13 | for j in range(1, m - l + 2) : 14 | k = int((a[i + l - 1][j + l - 1] - a[i - 1][j + l - 1] - a[i + l - 1][j - 1] + a[i - 1][j - 1]) / (l * l)) 15 | print(k, end = ' ') 16 | print() 17 | 18 | ''' Do Xuan Huong 19 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 23 | @@@@@@@@@@##########################################@@@@@@@@@ 24 | @@@@@@@@##############################################@@@@@@@ 25 | @@@@@@#################################################@@@@@@ 26 | @@@@@####################################################@@@@ 27 | @@@%#####################@@@@@@@@@@@######################@@@ 28 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 29 | @@##################@@@@@@ @@@@@@##################@@ 30 | @@#################@@@@@ @@@@###################@ 31 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 32 | @ &@@@@ @@@@ .......@@ 33 | @@ @@@@@@ @@@@@@ .......@@ 34 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 35 | @@@ @@@@@@@@@@@ ......@@@@ 36 | @@@@ ......@@@@@ 37 | @@@@@@ ......@@@@@@ 38 | @@@@@@@ .....@@@@@@@@ 39 | @@@@@@@@@ .....@@@@@@@@@@ 40 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 44 | ''' 45 | -------------------------------------------------------------------------------- /PY02069 - SỐ THUẬN NGHỊCHTRONG MA TRẬN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def tn(s) : 4 | if len(s) > 1 and s == s[::-1] : return 1 5 | return 0 6 | 7 | n, m = [int(x) for x in input().split()] 8 | a = [[0]] * n 9 | x = 0 10 | for i in range(n) : a[i] = input().split() 11 | for i in range(n) : 12 | for j in range(m) : 13 | if tn(a[i][j]) and int(a[i][j]) > int(x) : x = a[i][j] 14 | if x == 0 : print('NOT FOUND') 15 | else : print(x) 16 | for i in range(n) : 17 | for j in range(m) : 18 | if a[i][j] == x : print('Vi tri [', i, '][', j, ']', sep = '') 19 | -------------------------------------------------------------------------------- /PY02071 - TỔNG CÁC SỐ TỰ NHIÊN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, v, x = 0, [], [] 4 | 5 | def Try(k) : 6 | p = n - k 7 | if len(x) and x[-1] < p : 8 | p = x[-1] 9 | for i in range(p, 0, -1) : 10 | x.append(i) 11 | if i + k == n : 12 | v.append(x[:]) 13 | else : 14 | Try(k + i) 15 | x.pop() 16 | 17 | t = int(input()) 18 | for i in range(t) : 19 | x, v = [], [] 20 | n = int(input()) 21 | Try(0) 22 | print(len(v)) 23 | for j in v : 24 | print('(', j[0], sep = '', end = '') 25 | for k in range(1, len(j)) : 26 | print(' ', j[k], sep = '', end = '') 27 | print(')', end = ' ') 28 | print() 29 | 30 | ''' Do Xuan Huong 31 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 32 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 33 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 34 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 35 | @@@@@@@@@@##########################################@@@@@@@@@ 36 | @@@@@@@@##############################################@@@@@@@ 37 | @@@@@@#################################################@@@@@@ 38 | @@@@@####################################################@@@@ 39 | @@@%#####################@@@@@@@@@@@######################@@@ 40 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 41 | @@##################@@@@@@ @@@@@@##################@@ 42 | @@#################@@@@@ @@@@###################@ 43 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 44 | @ &@@@@ @@@@ .......@@ 45 | @@ @@@@@@ @@@@@@ .......@@ 46 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 47 | @@@ @@@@@@@@@@@ ......@@@@ 48 | @@@@ ......@@@@@ 49 | @@@@@@ ......@@@@@@ 50 | @@@@@@@ .....@@@@@@@@ 51 | @@@@@@@@@ .....@@@@@@@@@@ 52 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 53 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 54 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 55 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 56 | ''' 57 | -------------------------------------------------------------------------------- /PY02072 - ĐOẠN CON TRUNG BÌNH LỚN NHẤT: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) + 1 4 | a = [int(x) for x in input().split()] + [-1] 5 | ans, x, k = 0, 0, max(a) 6 | for i in range(n): 7 | if a[i] == k: 8 | x += 1 9 | else: 10 | ans = max(ans, x) 11 | x = 0 12 | print(ans) 13 | 14 | ''' Do Xuan Huong 15 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 19 | @@@@@@@@@@##########################################@@@@@@@@@ 20 | @@@@@@@@##############################################@@@@@@@ 21 | @@@@@@#################################################@@@@@@ 22 | @@@@@####################################################@@@@ 23 | @@@%#####################@@@@@@@@@@@######################@@@ 24 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 25 | @@##################@@@@@@ @@@@@@##################@@ 26 | @@#################@@@@@ @@@@###################@ 27 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 28 | @ &@@@@ @@@@ .......@@ 29 | @@ @@@@@@ @@@@@@ .......@@ 30 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 31 | @@@ @@@@@@@@@@@ ......@@@@ 32 | @@@@ ......@@@@@ 33 | @@@@@@ ......@@@@@@ 34 | @@@@@@@ .....@@@@@@@@ 35 | @@@@@@@@@ .....@@@@@@@@@@ 36 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 40 | ''' 41 | -------------------------------------------------------------------------------- /PY02073 - KÝ TỰ GIỐNG NHAU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class Data : 4 | def __init__(self, x, y): 5 | self.x = x 6 | self.y = y 7 | 8 | t = int(input()) 9 | for z in range(t): 10 | n = int(input()) 11 | a, q = [-1] * 110, [] 12 | x, y, z = [int(i) for i in input().split()] 13 | q.append(Data(0, 0)) 14 | a[0] = 0 15 | while len(q) > 0 : 16 | u = q[-1] 17 | q.pop() 18 | if u.x + 1 < 110 and (a[u.x + 1] == -1 or a[u.x + 1] > u.y + x) : 19 | a[u.x + 1] = a[u.x] + x 20 | q.append(Data(u.x + 1, u.y + x)) 21 | if u.x - 1 > 0 and (a[u.x - 1] == -1 or a[u.x - 1] > u.y + y) : 22 | a[u.x - 1] = a[u.x] + y 23 | q.append(Data(u.x - 1, u.y + y)) 24 | if u.x * 2 < 110 and (a[u.x * 2] == -1 or a[u.x * 2] > u.y + z) : 25 | a[u.x * 2] = a[u.x] + z 26 | q.append(Data(u.x * 2, u.y + z)) 27 | 28 | print(a[n]) 29 | 30 | ''' Do Xuan Huong 31 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 32 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 33 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 34 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 35 | @@@@@@@@@@##########################################@@@@@@@@@ 36 | @@@@@@@@##############################################@@@@@@@ 37 | @@@@@@#################################################@@@@@@ 38 | @@@@@####################################################@@@@ 39 | @@@%#####################@@@@@@@@@@@######################@@@ 40 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 41 | @@##################@@@@@@ @@@@@@##################@@ 42 | @@#################@@@@@ @@@@###################@ 43 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 44 | @ &@@@@ @@@@ .......@@ 45 | @@ @@@@@@ @@@@@@ .......@@ 46 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 47 | @@@ @@@@@@@@@@@ ......@@@@ 48 | @@@@ ......@@@@@ 49 | @@@@@@ ......@@@@@@ 50 | @@@@@@@ .....@@@@@@@@ 51 | @@@@@@@@@ .....@@@@@@@@@@ 52 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 53 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 54 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 55 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 56 | ''' 57 | -------------------------------------------------------------------------------- /PY02075 - TRỤC TỌA ĐỘ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class Line : 4 | def __init__(self, x, y) : 5 | self.x = x 6 | self.y = y 7 | 8 | t = int(input()) 9 | for z in range(t) : 10 | n = int(input()) 11 | a = [] 12 | for i in range(n) : 13 | x, y = [int(x) for x in input().split()] 14 | a.append(Line(x, y)) 15 | a = sorted(a, key = lambda k : k.y) 16 | s, k = 1, a[0].y 17 | for i in range(1, n) : 18 | if a[i].x >= k : 19 | s += 1 20 | k = a[i].y 21 | print(s) 22 | 23 | ''' Do Xuan Huong 24 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 27 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 28 | @@@@@@@@@@##########################################@@@@@@@@@ 29 | @@@@@@@@##############################################@@@@@@@ 30 | @@@@@@#################################################@@@@@@ 31 | @@@@@####################################################@@@@ 32 | @@@%#####################@@@@@@@@@@@######################@@@ 33 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 34 | @@##################@@@@@@ @@@@@@##################@@ 35 | @@#################@@@@@ @@@@###################@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 37 | @ &@@@@ @@@@ .......@@ 38 | @@ @@@@@@ @@@@@@ .......@@ 39 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 40 | @@@ @@@@@@@@@@@ ......@@@@ 41 | @@@@ ......@@@@@ 42 | @@@@@@ ......@@@@@@ 43 | @@@@@@@ .....@@@@@@@@ 44 | @@@@@@@@@ .....@@@@@@@@@@ 45 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 49 | ''' 50 | -------------------------------------------------------------------------------- /PY02078 - TĂNG - GIẢM: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n = int(input()) 6 | a, b, f, ans = [0] * n, [0] * n, [1] * n, 1 7 | for i in range(n) : 8 | a[i], b[i] = [float(x) for x in input().split()] 9 | for i in range(n) : 10 | for j in range(0, i) : 11 | if a[i] > a[j] and b[i] < b[j] : 12 | f[i] = max(f[i], f[j] + 1) 13 | ans = max(ans, f[i]) 14 | print(ans) 15 | 16 | ''' Do Xuan Huong 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 21 | @@@@@@@@@@##########################################@@@@@@@@@ 22 | @@@@@@@@##############################################@@@@@@@ 23 | @@@@@@#################################################@@@@@@ 24 | @@@@@####################################################@@@@ 25 | @@@%#####################@@@@@@@@@@@######################@@@ 26 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 27 | @@##################@@@@@@ @@@@@@##################@@ 28 | @@#################@@@@@ @@@@###################@ 29 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 30 | @ &@@@@ @@@@ .......@@ 31 | @@ @@@@@@ @@@@@@ .......@@ 32 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 33 | @@@ @@@@@@@@@@@ ......@@@@ 34 | @@@@ ......@@@@@ 35 | @@@@@@ ......@@@@@@ 36 | @@@@@@@ .....@@@@@@@@ 37 | @@@@@@@@@ .....@@@@@@@@@@ 38 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 | ''' 43 | -------------------------------------------------------------------------------- /PY03004 - THỐNG KÊ TỪ KHÁC NHAU: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = {} 3 | for k in range(n) : 4 | s = '' 5 | for i in input().lower() + ' ' : 6 | if (i >= 'a' and i <= 'z') or (i >= '0' and i <= '9') : s += i 7 | else : 8 | if(s != '') : 9 | if s in m : m[s] += 1 10 | else : m[s] = 1 11 | s = '' 12 | m = sorted(m.items(), key = lambda x: (-x[1], x[0])) 13 | for i in m : 14 | print(i[0], i[1]) 15 | 16 | ''' Do Xuan Huong 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 21 | @@@@@@@@@@##########################################@@@@@@@@@ 22 | @@@@@@@@##############################################@@@@@@@ 23 | @@@@@@#################################################@@@@@@ 24 | @@@@@####################################################@@@@ 25 | @@@%#####################@@@@@@@@@@@######################@@@ 26 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 27 | @@##################@@@@@@ @@@@@@##################@@ 28 | @@#################@@@@@ @@@@###################@ 29 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 30 | @ &@@@@ @@@@ .......@@ 31 | @@ @@@@@@ @@@@@@ .......@@ 32 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 33 | @@@ @@@@@@@@@@@ ......@@@@ 34 | @@@@ ......@@@@@ 35 | @@@@@@ ......@@@@@@ 36 | @@@@@@@ .....@@@@@@@@ 37 | @@@@@@@@@ .....@@@@@@@@@@ 38 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 | ''' 43 | -------------------------------------------------------------------------------- /PY03005 - THỐNG KÊ TỪ KHÁC NHAU THEO NGƯỠNG K: -------------------------------------------------------------------------------- 1 | n, k = [int(x) for x in input().split()] 2 | m = {} 3 | for z in range(n) : 4 | s = '' 5 | for i in input().lower() + ' ' : 6 | if not(i.isalpha()) and not(i.isdigit()) : 7 | if(s != '') : 8 | if s in m : m[s] += 1 9 | else : m[s] = 1 10 | s = '' 11 | else : s += i 12 | m = sorted(m.items(), key = lambda x: (-x[1], x[0])) 13 | for i in m : 14 | if i[1] >= k : print(i[0], i[1]) 15 | 16 | ''' Do Xuan Huong 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 21 | @@@@@@@@@@##########################################@@@@@@@@@ 22 | @@@@@@@@##############################################@@@@@@@ 23 | @@@@@@#################################################@@@@@@ 24 | @@@@@####################################################@@@@ 25 | @@@%#####################@@@@@@@@@@@######################@@@ 26 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 27 | @@##################@@@@@@ @@@@@@##################@@ 28 | @@#################@@@@@ @@@@###################@ 29 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 30 | @ &@@@@ @@@@ .......@@ 31 | @@ @@@@@@ @@@@@@ .......@@ 32 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 33 | @@@ @@@@@@@@@@@ ......@@@@ 34 | @@@@ ......@@@@@ 35 | @@@@@@ ......@@@@@@ 36 | @@@@@@@ .....@@@@@@@@ 37 | @@@@@@@@@ .....@@@@@@@@@@ 38 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 | ''' 43 | -------------------------------------------------------------------------------- /PY03006 - THỐNG KÊ TỪ KHÁC NHAU KHÔNG CHỨA CHỮ SỐ: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = {} 3 | for k in range(n) : 4 | s = '' 5 | for i in input().lower() + ' ' : 6 | if not(i.isalpha()) : 7 | if(s != '') : 8 | if s in m : m[s] += 1 9 | else : m[s] = 1 10 | s = '' 11 | else : s += i 12 | m = sorted(m.items(), key = lambda x: (-x[1], x[0])) 13 | for i in m : 14 | print(i[0], i[1]) 15 | 16 | ''' Do Xuan Huong 17 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 21 | @@@@@@@@@@##########################################@@@@@@@@@ 22 | @@@@@@@@##############################################@@@@@@@ 23 | @@@@@@#################################################@@@@@@ 24 | @@@@@####################################################@@@@ 25 | @@@%#####################@@@@@@@@@@@######################@@@ 26 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 27 | @@##################@@@@@@ @@@@@@##################@@ 28 | @@#################@@@@@ @@@@###################@ 29 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 30 | @ &@@@@ @@@@ .......@@ 31 | @@ @@@@@@ @@@@@@ .......@@ 32 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 33 | @@@ @@@@@@@@@@@ ......@@@@ 34 | @@@@ ......@@@@@ 35 | @@@@@@ ......@@@@@@ 36 | @@@@@@@ .....@@@@@@@@ 37 | @@@@@@@@@ .....@@@@@@@@@@ 38 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 | ''' 43 | -------------------------------------------------------------------------------- /PY03007 - XỬ LÝ VĂN BẢN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import re 4 | 5 | s = "" 6 | regex = '[\w\s,:]+' 7 | while True: 8 | try : s += input() 9 | except EOFError : break 10 | s = re.findall(regex, s) 11 | for i in s: 12 | x = i.lower().split() 13 | x[0] = x[0].title() 14 | print(' '.join(x)) 15 | -------------------------------------------------------------------------------- /PY03008 - ĐỒ THỊ HÌNH SAO: -------------------------------------------------------------------------------- 1 | n, m, ok = int(input()), {}, 1 2 | for i in range(n - 1) : 3 | x, y = [int(x) for x in input().split()] 4 | if x in m : m[x] += 1 5 | else : m[x] = 1 6 | if y in m : m[y] += 1 7 | else : m[y] = 1 8 | for i in range(1, n + 1) : 9 | if not(i in m) or (m[i] != 1 and m[i] != n - 1) : 10 | ok = 0 11 | print("No") 12 | break 13 | if ok == 1 : print("Yes") 14 | 15 | ''' Do Xuan Huong 16 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 20 | @@@@@@@@@@##########################################@@@@@@@@@ 21 | @@@@@@@@##############################################@@@@@@@ 22 | @@@@@@#################################################@@@@@@ 23 | @@@@@####################################################@@@@ 24 | @@@%#####################@@@@@@@@@@@######################@@@ 25 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 26 | @@##################@@@@@@ @@@@@@##################@@ 27 | @@#################@@@@@ @@@@###################@ 28 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 29 | @ &@@@@ @@@@ .......@@ 30 | @@ @@@@@@ @@@@@@ .......@@ 31 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 32 | @@@ @@@@@@@@@@@ ......@@@@ 33 | @@@@ ......@@@@@ 34 | @@@@@@ ......@@@@@@ 35 | @@@@@@@ .....@@@@@@@@ 36 | @@@@@@@@@ .....@@@@@@@@@@ 37 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 41 | ''' 42 | -------------------------------------------------------------------------------- /PY03012 - BẢNG XẾP HẠNG: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import functools 4 | 5 | class SV : 6 | def __init__(self, name, ac, submit): 7 | self.name = name 8 | self.ac = ac 9 | self.submit = submit 10 | 11 | def cmp(a, b) : 12 | if a.ac < b.ac : return 1 13 | elif a.ac == b.ac : 14 | if a.submit > b.submit : return 1 15 | elif a.submit == b.submit : 16 | if a.name > b.name : return 1 17 | else : return -1 18 | else : return -1 19 | else : return -1 20 | 21 | n = int(input()) 22 | a = [] 23 | for i in range(n) : 24 | name = input() 25 | ac, submit = [int(x) for x in input().split()] 26 | a.append(SV(name, ac, submit)) 27 | a = sorted(a, key = functools.cmp_to_key(cmp)) 28 | for i in a : 29 | print(i.name, i.ac, i.submit) 30 | -------------------------------------------------------------------------------- /PY03014 - BIỂU THỨC: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | for k in range(t) : 3 | a = input() 4 | d, id = [], 1 5 | for i in a : 6 | if i == '(' : 7 | print(id, end = ' ') 8 | d.append(id) 9 | id += 1 10 | elif i == ')': 11 | print(d[-1], end = ' ') 12 | d.pop() 13 | print() 14 | 15 | ''' Do Xuan Huong 16 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 18 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 20 | @@@@@@@@@@##########################################@@@@@@@@@ 21 | @@@@@@@@##############################################@@@@@@@ 22 | @@@@@@#################################################@@@@@@ 23 | @@@@@####################################################@@@@ 24 | @@@%#####################@@@@@@@@@@@######################@@@ 25 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 26 | @@##################@@@@@@ @@@@@@##################@@ 27 | @@#################@@@@@ @@@@###################@ 28 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 29 | @ &@@@@ @@@@ .......@@ 30 | @@ @@@@@@ @@@@@@ .......@@ 31 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 32 | @@@ @@@@@@@@@@@ ......@@@@ 33 | @@@@ ......@@@@@ 34 | @@@@@@ ......@@@@@@ 35 | @@@@@@@ .....@@@@@@@@ 36 | @@@@@@@@@ .....@@@@@@@@@@ 37 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 41 | ''' 42 | -------------------------------------------------------------------------------- /PY04001 - LỚP POINT: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | from decimal import Decimal 5 | 6 | class Point : 7 | def __init__(self, x, y): 8 | self.x = x 9 | self.y = y 10 | def distance(self, k) : 11 | x0 = self.x - k.x 12 | y0 = self.y - k.y 13 | f = math.sqrt(x0 * x0 + y0 * y0) 14 | return "{:.4f}".format(f) 15 | 16 | if __name__ == '__main__': 17 | t = int(input()) 18 | while t > 0: 19 | arr = input().split() 20 | p1 = Point(Decimal(arr[0]), Decimal(arr[1])) 21 | p2 = Point(Decimal(arr[2]), Decimal(arr[3])) 22 | print(p1.distance(p2)) 23 | t -= 1 24 | -------------------------------------------------------------------------------- /PY04002 - LỚP RECTANGLE: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class Rectangle : 4 | def __init__(self, w, h, color) : 5 | self.w = w 6 | self.h = h 7 | self.color = color[0:1:].upper() + color[1::].lower() 8 | 9 | def check(self) : 10 | if self.w <= 0 or self.h <=0 : return 0 11 | return 1 12 | 13 | def output(self) : 14 | if self.check() == 1 : print((self.w + self.h) * 2, self.w * self.h, self.color, sep = ' ') 15 | else : print('INVALID') 16 | 17 | a = input().split() 18 | rec = Rectangle(int(a[0]), int(a[1]), (a[2])) 19 | rec.output() 20 | -------------------------------------------------------------------------------- /PY04003 - LỚP PHÂN SỐ - 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | class Fraction : 6 | def __init__(self, numerator, denominator): 7 | self.numerator = numerator 8 | self.denominator = denominator 9 | def compact(self) : 10 | k = math.gcd(self.numerator, self.denominator) 11 | self.numerator = int(self.numerator / k) 12 | self.denominator = int(self.denominator / k) 13 | def output(self) : 14 | print(self.numerator, "/", self.denominator, sep = "") 15 | 16 | a, b = [int(x) for x in input().split()] 17 | f = Fraction(a, b) 18 | f.compact() 19 | f.output() 20 | -------------------------------------------------------------------------------- /PY04004 - LỚP PHÂN SỐ - 2: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | class Fraction : 6 | def __init__(self, numerator, denominator): 7 | self.numerator = numerator 8 | self.denominator = denominator 9 | def compact(self) : 10 | k = math.gcd(self.numerator, self.denominator) 11 | self.numerator = int(self.numerator / k) 12 | self.denominator = int(self.denominator / k) 13 | def add(self, x) : 14 | a = self.denominator * x.numerator + x.denominator * self.numerator 15 | b = self.denominator * x.denominator 16 | self.numerator = a 17 | self.denominator = b 18 | def output(self) : 19 | print(self.numerator, "/", self.denominator, sep = "") 20 | 21 | f = [int(x) for x in input().split()] 22 | a = Fraction(f[0], f[1]) 23 | b = Fraction(f[2], f[3]) 24 | a.add(b) 25 | a.compact() 26 | a.output() 27 | -------------------------------------------------------------------------------- /PY04005 - LỚP TRIANGLE - 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | class Point : 6 | def __init__(self, x, y): 7 | self.x = x 8 | self.y = y 9 | def distance(self, k) : 10 | x0 = self.x - k.x 11 | y0 = self.y - k.y 12 | return math.sqrt(x0 * x0 + y0 * y0) 13 | 14 | class Triangle : 15 | def __init__(self, p1, p2, p3): 16 | self.p1 = p1 17 | self.p2 = p2 18 | self.p3 = p3 19 | def cnt(self) : 20 | a = self.p1.distance(self.p2) 21 | b = self.p2.distance(self.p3) 22 | c = self.p1.distance(self.p3) 23 | if(max(a, b, c) * 2 >= a + b + c) : print('INVALID') 24 | else : print('{:.3f}'.format(a + b + c)) 25 | 26 | a = [] 27 | t = int(input()) 28 | for x in range(t): 29 | a += [float(i) for i in input().split()] 30 | i = 0 31 | for index in range(t): 32 | triagle = Triangle(Point(a[i], a[i+1]), Point(a[i+2], a[i+3]), Point(a[i+4], a[i+5])) 33 | triagle.cnt() 34 | i += 6 35 | 36 | ''' Do Xuan Huong 37 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 39 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 41 | @@@@@@@@@@##########################################@@@@@@@@@ 42 | @@@@@@@@##############################################@@@@@@@ 43 | @@@@@@#################################################@@@@@@ 44 | @@@@@####################################################@@@@ 45 | @@@%#####################@@@@@@@@@@@######################@@@ 46 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 47 | @@##################@@@@@@ @@@@@@##################@@ 48 | @@#################@@@@@ @@@@###################@ 49 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 50 | @ &@@@@ @@@@ .......@@ 51 | @@ @@@@@@ @@@@@@ .......@@ 52 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 53 | @@@ @@@@@@@@@@@ ......@@@@ 54 | @@@@ ......@@@@@ 55 | @@@@@@ ......@@@@@@ 56 | @@@@@@@ .....@@@@@@@@ 57 | @@@@@@@@@ .....@@@@@@@@@@ 58 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 59 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 60 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 61 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 62 | ''' 63 | -------------------------------------------------------------------------------- /PY04006 - LỚP TRIANGLE - 2: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import math 4 | 5 | class Point : 6 | def __init__(self, x, y): 7 | self.x = x 8 | self.y = y 9 | def distance(self, k) : 10 | x0 = self.x - k.x 11 | y0 = self.y - k.y 12 | return math.sqrt(x0 * x0 + y0 * y0) 13 | 14 | class Triangle : 15 | def __init__(self, p1, p2, p3): 16 | self.p1 = p1 17 | self.p2 = p2 18 | self.p3 = p3 19 | def cnt(self) : 20 | a = self.p1.distance(self.p2) 21 | b = self.p2.distance(self.p3) 22 | c = self.p1.distance(self.p3) 23 | if(max(a, b, c) * 2 >= a + b + c) : print('INVALID') 24 | else : 25 | d = math.sqrt((a + b + c) * (a + b - c) * (a - b + c) * (-a + b + c)) / 4 26 | print('{:.2f}'.format(d)) 27 | 28 | a = [] 29 | t = int(input()) 30 | for x in range(t): 31 | a += [float(i) for i in input().split()] 32 | i = 0 33 | for index in range(t): 34 | triagle = Triangle(Point(a[i], a[i+1]), Point(a[i+2], a[i+3]), Point(a[i+4], a[i+5])) 35 | triagle.cnt() 36 | i += 6 37 | 38 | ''' Do Xuan Huong 39 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 43 | @@@@@@@@@@##########################################@@@@@@@@@ 44 | @@@@@@@@##############################################@@@@@@@ 45 | @@@@@@#################################################@@@@@@ 46 | @@@@@####################################################@@@@ 47 | @@@%#####################@@@@@@@@@@@######################@@@ 48 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 49 | @@##################@@@@@@ @@@@@@##################@@ 50 | @@#################@@@@@ @@@@###################@ 51 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 52 | @ &@@@@ @@@@ .......@@ 53 | @@ @@@@@@ @@@@@@ .......@@ 54 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 55 | @@@ @@@@@@@@@@@ ......@@@@ 56 | @@@@ ......@@@@@ 57 | @@@@@@ ......@@@@@@ 58 | @@@@@@@ .....@@@@@@@@ 59 | @@@@@@@@@ .....@@@@@@@@@@ 60 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 61 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 62 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 63 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 64 | ''' 65 | -------------------------------------------------------------------------------- /PY04007 - LỚP MATRIX - 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for k in range(t) : 5 | n, m = [int(x) for x in input().split()] 6 | a, b = [[0] * m] * n, [] 7 | for i in range(n) : 8 | a[i] = [int(x) for x in input().split()] 9 | for i in range(m) : 10 | x = [] 11 | for j in range(n) : 12 | x.append(a[j][i]) 13 | b.append(x) 14 | for i in range(n) : 15 | for j in range(n) : 16 | s = 0 17 | for z in range(m) : 18 | s += a[i][z] * b[z][j] 19 | print(s, end = ' ') 20 | print() 21 | -------------------------------------------------------------------------------- /PY04009 - LỚP SỐ PHỨC: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for k in range(t) : 5 | a, b, c, d = [int(x) for x in input().split()] 6 | x = a * a + a * c - b * b - b * d 7 | y = a * b + b * c + a * b + a * d 8 | z = (a + c) * (a + c) - (b + d) * (b + d) 9 | t = 2 * (a + c) * (b + d) 10 | print(x, end = '') 11 | if y > 0 : print(' + ', end = '') 12 | else : print(' - ', end = '') 13 | print(abs(y), 'i', sep = '', end = '') 14 | print(',', z, end = '') 15 | if t > 0 : print(' + ', end = '') 16 | else : print(' - ', end = '') 17 | print(abs(t), 'i', sep = '') 18 | 19 | ''' Do Xuan Huong 20 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 24 | @@@@@@@@@@##########################################@@@@@@@@@ 25 | @@@@@@@@##############################################@@@@@@@ 26 | @@@@@@#################################################@@@@@@ 27 | @@@@@####################################################@@@@ 28 | @@@%#####################@@@@@@@@@@@######################@@@ 29 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 30 | @@##################@@@@@@ @@@@@@##################@@ 31 | @@#################@@@@@ @@@@###################@ 32 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 33 | @ &@@@@ @@@@ .......@@ 34 | @@ @@@@@@ @@@@@@ .......@@ 35 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 36 | @@@ @@@@@@@@@@@ ......@@@@ 37 | @@@@ ......@@@@@ 38 | @@@@@@ ......@@@@@@ 39 | @@@@@@@ .....@@@@@@@@ 40 | @@@@@@@@@ .....@@@@@@@@@@ 41 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 45 | ''' 46 | -------------------------------------------------------------------------------- /PY04010 - LỚP THÍ SINH - 1: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class ThiSinh : 4 | tongDiem = 0 5 | def __init__(self, hoTen, ngaySinh, diem1, diem2, diem3) : 6 | self.hoTen = hoTen 7 | self.ngaySinh = ngaySinh 8 | self.diem1 = diem1 9 | self.diem2 = diem2 10 | self.diem3 = diem3 11 | self.tongDiem = diem1 + diem2 + diem3 12 | 13 | def output(self) : 14 | print(self.hoTen, self.ngaySinh, "{:.1f}".format(self.tongDiem)) 15 | 16 | ht = input() 17 | ns = input() 18 | d1 = float(input()) 19 | d2 = float(input()) 20 | d3 = float(input()) 21 | ts = ThiSinh(ht, ns, d1, d2, d3) 22 | ts.output() 23 | -------------------------------------------------------------------------------- /PY04012 - TÍNH ĐIỂM CHUYÊN CẦN: -------------------------------------------------------------------------------- 1 | t = int(input()) 2 | m = {} 3 | for i in range(t) : 4 | maSV = input() 5 | ten = input() 6 | lop = input() 7 | m[maSV] = [ten, lop] 8 | for i in range(t) : 9 | maSV, cc = input().split() 10 | d = 10 11 | for j in cc : 12 | if j == 'm' : d -= 1 13 | elif j == 'v' : d -= 2 14 | if d < 0 : d = 0 15 | m[maSV] = m[maSV] + [d] 16 | for i in m : 17 | print(i, end = ' ') 18 | for j in m[i] : 19 | print(j, end = ' ') 20 | if(m[i][-1] == 0) : print('KDDK') 21 | else : print() 22 | 23 | ''' Do Xuan Huong 24 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 27 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 28 | @@@@@@@@@@##########################################@@@@@@@@@ 29 | @@@@@@@@##############################################@@@@@@@ 30 | @@@@@@#################################################@@@@@@ 31 | @@@@@####################################################@@@@ 32 | @@@%#####################@@@@@@@@@@@######################@@@ 33 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 34 | @@##################@@@@@@ @@@@@@##################@@ 35 | @@#################@@@@@ @@@@###################@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 37 | @ &@@@@ @@@@ .......@@ 38 | @@ @@@@@@ @@@@@@ .......@@ 39 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 40 | @@@ @@@@@@@@@@@ ......@@@@ 41 | @@@@ ......@@@@@ 42 | @@@@@@ ......@@@@@@ 43 | @@@@@@@ .....@@@@@@@@ 44 | @@@@@@@@@ .....@@@@@@@@@@ 45 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 49 | ''' 50 | -------------------------------------------------------------------------------- /PY04013 - TÍNH TOÁN LƯỢNG MƯA: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def time(x, y): 4 | return y[0] * 60 + y[1] - x[0] * 60 - x[1] 5 | 6 | a = {} 7 | n = int(input()) 8 | for i in range(n) : 9 | ten = input() 10 | x = [int(i) for i in input().split(':')] 11 | y = [int(i) for i in input().split(':')] 12 | luongMua = int(input()) 13 | if ten not in a: 14 | a[ten] = (time(x, y), luongMua) 15 | else: 16 | a[ten] = (a[ten][0] + time(x, y), a[ten][1] + luongMua) 17 | 18 | p = 1 19 | for i in a: 20 | print('T{:02d}'.format(p), i, "{:.2f}".format(a[i][1] * 60 / a[i][0])) 21 | p += 1 22 | -------------------------------------------------------------------------------- /PY04014 - BẢNG ĐIỂM: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | from decimal import ROUND_HALF_UP, Decimal 4 | 5 | id = 1 6 | class HocSinh : 7 | maHS = 'HS' 8 | diemTrungBinh = 0 9 | xepLoai = '' 10 | def __init__(self, ten, diem) : 11 | global id 12 | self.maHS += '{:02d}'.format(id) 13 | id += 1 14 | self.ten = ten 15 | x = 2 * diem[0] + 2 * diem[1] 16 | for i in range(2, 10) : 17 | x += diem[i] 18 | x /= 12 19 | if x < 5 : self.xepLoai = 'YEU' 20 | elif x < 7 : self.xepLoai = 'TB' 21 | elif x < 8 : self.xepLoai = 'KHA' 22 | elif x < 9 : self.xepLoai = 'GIOI' 23 | else : self.xepLoai = 'XUAT SAC' 24 | self.diemTrungBinh = x.quantize(Decimal('0.1'), ROUND_HALF_UP) 25 | 26 | def output(self) : 27 | print(self.maHS, self.ten, self.diemTrungBinh, self.xepLoai) 28 | 29 | n = int(input()) 30 | a = [] 31 | for i in range(n) : 32 | b = input() 33 | c = [Decimal(x) for x in input().split()] 34 | a.append(HocSinh(b, c)) 35 | 36 | a = sorted(a, key= lambda x : (- x.diemTrungBinh, x.maHS)) 37 | for i in a : 38 | i.output() 39 | 40 | ''' Do Xuan Huong 41 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 45 | @@@@@@@@@@##########################################@@@@@@@@@ 46 | @@@@@@@@##############################################@@@@@@@ 47 | @@@@@@#################################################@@@@@@ 48 | @@@@@####################################################@@@@ 49 | @@@%#####################@@@@@@@@@@@######################@@@ 50 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 51 | @@##################@@@@@@ @@@@@@##################@@ 52 | @@#################@@@@@ @@@@###################@ 53 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 54 | @ &@@@@ @@@@ .......@@ 55 | @@ @@@@@@ @@@@@@ .......@@ 56 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 57 | @@@ @@@@@@@@@@@ ......@@@@ 58 | @@@@ ......@@@@@ 59 | @@@@@@ ......@@@@@@ 60 | @@@@@@@ .....@@@@@@@@ 61 | @@@@@@@@@ .....@@@@@@@@@@ 62 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 63 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 64 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 65 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 66 | ''' 67 | -------------------------------------------------------------------------------- /PY04015 - LẬP HÓA ĐƠN - 1: -------------------------------------------------------------------------------- 1 | class HoaDon : 2 | tien = 0 3 | def __init__(self, ma, ten, cu, moi) : 4 | self.ma = ma 5 | self.ten = ten 6 | s = moi - cu 7 | if s <= 50: 8 | s *= 100 9 | s += s * 0.02 10 | elif s <= 100: 11 | s = 50 * 100 + (s - 50) * 150 12 | s += s * 0.03 13 | else: 14 | s = 50 * 100 + 50 * 150 + (s - 100) * 200 15 | s += s * 0.05 16 | self.tien = round(s) 17 | 18 | def output(self) : 19 | print(self.ma, self.ten, self.tien) 20 | 21 | n = int(input()) 22 | a = [] 23 | for i in range(n) : 24 | ten = input() 25 | ma = "KH{:02d}".format(i + 1) 26 | cu = int(input()) 27 | moi = int(input()) 28 | a.append(HoaDon(ma, ten, cu, moi)) 29 | 30 | a = sorted(a, key= lambda x : (-x.tien)) 31 | for i in a : 32 | i.output() 33 | 34 | ''' Do Xuan Huong 35 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 39 | @@@@@@@@@@##########################################@@@@@@@@@ 40 | @@@@@@@@##############################################@@@@@@@ 41 | @@@@@@#################################################@@@@@@ 42 | @@@@@####################################################@@@@ 43 | @@@%#####################@@@@@@@@@@@######################@@@ 44 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 45 | @@##################@@@@@@ @@@@@@##################@@ 46 | @@#################@@@@@ @@@@###################@ 47 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 48 | @ &@@@@ @@@@ .......@@ 49 | @@ @@@@@@ @@@@@@ .......@@ 50 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 51 | @@@ @@@@@@@@@@@ ......@@@@ 52 | @@@@ ......@@@@@ 53 | @@@@@@ ......@@@@@@ 54 | @@@@@@@ .....@@@@@@@@ 55 | @@@@@@@@@ .....@@@@@@@@@@ 56 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 57 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 58 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 59 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 60 | ''' 61 | -------------------------------------------------------------------------------- /PY04016 - LẬP HÓA ĐƠN - 2: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | from datetime import datetime 4 | 5 | tg = [0, 25, 34, 50, 80] 6 | 7 | class KhachHang : 8 | def __init__(self, id, ten, phong, ngayDen, ngayDi, phuThu) : 9 | self.id = 'KH{0:0>2}'.format(id) 10 | self.ten = ten 11 | self.phong = phong 12 | self.ngayO = str(datetime.strptime(ngayDi, '%d/%m/%Y') - datetime.strptime(ngayDen, '%d/%m/%Y')).split()[0] 13 | if self.ngayO == '0:00:00' : self.ngayO = 1 14 | else : self.ngayO = int(self.ngayO) + 1 15 | self.tong = tg[int(self.phong[0])] * self.ngayO + phuThu 16 | 17 | def __str__(self): 18 | return self.id + ' ' + self.ten + ' ' + self.phong + ' ' + str(self.ngayO) + ' ' + str(self.tong) 19 | 20 | n = int(input()) 21 | a = [] 22 | for i in range(n): 23 | a.append(KhachHang(i+1, input(), input(), input().strip(), input().strip(), int(input()))) 24 | a.sort(key = lambda k : -k.tong) 25 | print(*a, sep = '\n') 26 | 27 | ''' Do Xuan Huong 28 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 32 | @@@@@@@@@@##########################################@@@@@@@@@ 33 | @@@@@@@@##############################################@@@@@@@ 34 | @@@@@@#################################################@@@@@@ 35 | @@@@@####################################################@@@@ 36 | @@@%#####################@@@@@@@@@@@######################@@@ 37 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 38 | @@##################@@@@@@ @@@@@@##################@@ 39 | @@#################@@@@@ @@@@###################@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 41 | @ &@@@@ @@@@ .......@@ 42 | @@ @@@@@@ @@@@@@ .......@@ 43 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 44 | @@@ @@@@@@@@@@@ ......@@@@ 45 | @@@@ ......@@@@@ 46 | @@@@@@ ......@@@@@@ 47 | @@@@@@@ .....@@@@@@@@ 48 | @@@@@@@@@ .....@@@@@@@@@@ 49 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 52 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 53 | ''' 54 | -------------------------------------------------------------------------------- /PY04017 - TÍNH VẬN TỐC: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class CuaRo : 4 | def __init__(self, ten, donVi, thoiGian) : 5 | a = [i[0] for i in ten.split()] 6 | b = [i[0] for i in donVi.split()] 7 | self.id = ''.join(b) + ''.join(a) 8 | self.ten = ten 9 | self.donVi = donVi 10 | c = thoiGian.split(':') 11 | self.vanToc = 120 / (int(c[0]) - 6 + int(c[1]) / 60) 12 | 13 | def __str__(self) : 14 | return f"{self.id} {self.ten} {self.donVi} {round(self.vanToc)} Km/h" 15 | 16 | n = int(input()) 17 | cuaRo = [] 18 | for i in range(n) : 19 | cuaRo.append(CuaRo(input(), input(), input())) 20 | cuaRo = sorted(cuaRo, key = lambda x : -x.vanToc) 21 | print(*cuaRo, sep = '\n') 22 | 23 | ''' Do Xuan Huong 24 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 27 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 28 | @@@@@@@@@@##########################################@@@@@@@@@ 29 | @@@@@@@@##############################################@@@@@@@ 30 | @@@@@@#################################################@@@@@@ 31 | @@@@@####################################################@@@@ 32 | @@@%#####################@@@@@@@@@@@######################@@@ 33 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 34 | @@##################@@@@@@ @@@@@@##################@@ 35 | @@#################@@@@@ @@@@###################@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 37 | @ &@@@@ @@@@ .......@@ 38 | @@ @@@@@@ @@@@@@ .......@@ 39 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 40 | @@@ @@@@@@@@@@@ ......@@@@ 41 | @@@@ ......@@@@@ 42 | @@@@@@ ......@@@@@@ 43 | @@@@@@@ .....@@@@@@@@ 44 | @@@@@@@@@ .....@@@@@@@@@@ 45 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 49 | ''' 50 | -------------------------------------------------------------------------------- /PY04018 - XÁC ĐỊNH TRÚNG TUYỂN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | mon = ['TOAN', 'LY', 'HOA'] 4 | cong = [2, 1.5, 1, 0] 5 | 6 | class GV : 7 | def __init__(self, id, ten, ma, d1, d2) : 8 | self.id = 'GV{0:0>2}'.format(id) 9 | self.ten = ten 10 | self.mon = mon[ord(ma[0]) - ord('A')] 11 | self.d = 2 * d1 + d2 + cong[int(ma[1]) - 1] 12 | def __str__(self) : 13 | s = self.id + ' ' + self.ten + ' ' + self.mon + ' ' + str(self.d) 14 | if self.d >= 18 : s += ' TRUNG TUYEN' 15 | else : s += ' LOAI' 16 | return s 17 | 18 | n = int(input()) 19 | ds = [] 20 | for i in range(n) : 21 | ds.append(GV(i + 1, input(), input(), float(input()), float(input()))) 22 | ds = sorted(ds, key = lambda x : -x.d) 23 | print(*ds, sep = '\n') 24 | 25 | 26 | ''' Do Xuan Huong 27 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 28 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 31 | @@@@@@@@@@##########################################@@@@@@@@@ 32 | @@@@@@@@##############################################@@@@@@@ 33 | @@@@@@#################################################@@@@@@ 34 | @@@@@####################################################@@@@ 35 | @@@%#####################@@@@@@@@@@@######################@@@ 36 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 37 | @@##################@@@@@@ @@@@@@##################@@ 38 | @@#################@@@@@ @@@@###################@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 40 | @ &@@@@ @@@@ .......@@ 41 | @@ @@@@@@ @@@@@@ .......@@ 42 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 43 | @@@ @@@@@@@@@@@ ......@@@@ 44 | @@@@ ......@@@@@ 45 | @@@@@@ ......@@@@@@ 46 | @@@@@@@ .....@@@@@@@@ 47 | @@@@@@@@@ .....@@@@@@@@@@ 48 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 49 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 52 | ''' 53 | -------------------------------------------------------------------------------- /PY04019 - TUYỂN NHÂN VIÊN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class NhanVien : 4 | def __init__(self, id, ten, d1, d2) : 5 | self.id = 'TS0' + str(id) 6 | self.ten = ten 7 | if d1 > 10 : d1 /= 10 8 | if d2 > 10 : d2 /= 10 9 | self.d = (d1 + d2) / 2 10 | if self.d < 5 : self.l = 'TRUOT' 11 | elif self.d < 8 : self.l = 'CAN NHAC' 12 | elif self.d < 9.5 : self.l = 'DAT' 13 | else : self.l = 'XUAT SAC' 14 | 15 | n = int(input()) 16 | a = [] 17 | for i in range(n) : 18 | ten = input() 19 | d1 = float(input()) 20 | d2 = float(input()) 21 | a.append(NhanVien(i + 1, ten, d1, d2)) 22 | a.sort(key = lambda x : x.d, reverse = True) 23 | for i in a : 24 | print(i.id, i.ten, '{:.2f}'.format(i.d), i.l) 25 | 26 | ''' Do Xuan Huong 27 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 28 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 31 | @@@@@@@@@@##########################################@@@@@@@@@ 32 | @@@@@@@@##############################################@@@@@@@ 33 | @@@@@@#################################################@@@@@@ 34 | @@@@@####################################################@@@@ 35 | @@@%#####################@@@@@@@@@@@######################@@@ 36 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 37 | @@##################@@@@@@ @@@@@@##################@@ 38 | @@#################@@@@@ @@@@###################@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 40 | @ &@@@@ @@@@ .......@@ 41 | @@ @@@@@@ @@@@@@ .......@@ 42 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 43 | @@@ @@@@@@@@@@@ ......@@@@ 44 | @@@@ ......@@@@@ 45 | @@@@@@ ......@@@@@@ 46 | @@@@@@@ .....@@@@@@@@ 47 | @@@@@@@@@ .....@@@@@@@@@@ 48 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 49 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 52 | ''' 53 | -------------------------------------------------------------------------------- /PY04020 - LẬP HÓA ĐƠN - 3: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class MatHang : 4 | tongtien = 0 5 | def __init__(self, ma, ten, soluong, gia, chietkhau) : 6 | self.ma = ma 7 | self.ten = ten 8 | self.soluong = soluong 9 | self.gia = gia 10 | self.chietkhau = chietkhau 11 | self.tongtien = self.soluong * self.gia - self.chietkhau 12 | def __str__(self) : 13 | return self.ma + " " + self.ten + " " + str(self.soluong) + " " + str(self.gia) + " " + str(self.chietkhau) + " " + str(self.tongtien) 14 | 15 | n = int(input()) 16 | a = [] 17 | for i in range(n) : 18 | ma = input() 19 | ten = input() 20 | soluong = int(input()) 21 | gia = int(input()) 22 | chietkhau = int(input()) 23 | a.append(MatHang(ma, ten, soluong, gia, chietkhau)) 24 | a = sorted(a, key = lambda x : -x.tongtien) 25 | for i in a : 26 | print(i) 27 | 28 | ''' Do Xuan Huong 29 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 32 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 33 | @@@@@@@@@@##########################################@@@@@@@@@ 34 | @@@@@@@@##############################################@@@@@@@ 35 | @@@@@@#################################################@@@@@@ 36 | @@@@@####################################################@@@@ 37 | @@@%#####################@@@@@@@@@@@######################@@@ 38 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 39 | @@##################@@@@@@ @@@@@@##################@@ 40 | @@#################@@@@@ @@@@###################@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 42 | @ &@@@@ @@@@ .......@@ 43 | @@ @@@@@@ @@@@@@ .......@@ 44 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 45 | @@@ @@@@@@@@@@@ ......@@@@ 46 | @@@@ ......@@@@@ 47 | @@@@@@ ......@@@@@@ 48 | @@@@@@@ .....@@@@@@@@ 49 | @@@@@@@@@ .....@@@@@@@@@@ 50 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 52 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 53 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 54 | ''' 55 | -------------------------------------------------------------------------------- /PY04021 - TÍNH TOÁN THỜI GIAN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | class Gamer : 4 | thoiGian = 0 5 | def __init__(self, ma, ten, gioVao, gioRa) : 6 | self.ma = ma 7 | self.ten = ten 8 | self.thoiGian = gioRa[0] * 60 + gioRa[1] - gioVao[0] * 60 - gioVao[1] 9 | 10 | def output(self) : 11 | print(self.ma, self.ten, int(self.thoiGian / 60), 'gio', self.thoiGian % 60, 'phut') 12 | 13 | n = int(input()) 14 | a = [] 15 | for i in range(n) : 16 | ma = input() 17 | ten = input() 18 | gioVao = [int(x) for x in input().split(':')] 19 | gioRa = [int(x) for x in input().split(':')] 20 | a.append(Gamer(ma, ten, gioVao, gioRa)) 21 | 22 | a = sorted(a, key= lambda x : (- x.thoiGian)) 23 | for i in a : 24 | i.output() 25 | 26 | ''' Do Xuan Huong 27 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 28 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 31 | @@@@@@@@@@##########################################@@@@@@@@@ 32 | @@@@@@@@##############################################@@@@@@@ 33 | @@@@@@#################################################@@@@@@ 34 | @@@@@####################################################@@@@ 35 | @@@%#####################@@@@@@@@@@@######################@@@ 36 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 37 | @@##################@@@@@@ @@@@@@##################@@ 38 | @@#################@@@@@ @@@@###################@ 39 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 40 | @ &@@@@ @@@@ .......@@ 41 | @@ @@@@@@ @@@@@@ .......@@ 42 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 43 | @@@ @@@@@@@@@@@ ......@@@@ 44 | @@@@ ......@@@@@ 45 | @@@@@@ ......@@@@@@ 46 | @@@@@@@ .....@@@@@@@@ 47 | @@@@@@@@@ .....@@@@@@@@@@ 48 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 49 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 52 | ''' 53 | -------------------------------------------------------------------------------- /PYKT037 - ĐỔI CƠ SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | f = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' 4 | t = int(input()) 5 | for i in range(t): 6 | n, k = [int(x) for x in input().split()] 7 | s = '' 8 | while (n > 0): 9 | x = n % k 10 | s = f[x] + s 11 | n = int(n / k) 12 | print(s) 13 | -------------------------------------------------------------------------------- /PYKT038 - HỆ CƠ SỐ 8: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | a = int(input(), 2) 4 | print(oct(a)[2::]) 5 | -------------------------------------------------------------------------------- /PYKT039 - DÃY SỐ PHÙ HỢP: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def check(n, a, b) : 4 | for i in range(n) : 5 | if a[i] > b[i] : return 0 6 | return 1 7 | 8 | t = int(input()) 9 | for z in range(t) : 10 | n = int(input()) 11 | a = sorted([int(x) for x in input().split()]) 12 | b = sorted([int(x) for x in input().split()]) 13 | if check(n, a, b) == 1 : print("YES") 14 | else : print("NO") 15 | -------------------------------------------------------------------------------- /PYKT041 - ĐẾM CẶP ĐỒNG XU: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n = int(input()) 4 | a = [''] * n 5 | b = [0] * n 6 | c = [0] * n 7 | s = 0 8 | for i in range(n) : 9 | a[i] = input() 10 | for i in range(n) : 11 | for j in range(n) : 12 | if a[i][j] == 'C' : 13 | b[i] += 1 14 | c[j] += 1 15 | for i in range(n) : 16 | s += b[i] * (b[i] - 1) / 2 17 | s += c[i] * (c[i] - 1) / 2 18 | print(int(s)) 19 | -------------------------------------------------------------------------------- /PYKT058 - ĐỈNH THẮT: -------------------------------------------------------------------------------- 1 | def check(n, k, u, v, ke) : 2 | q, a = [u], [0] * (n + 1) 3 | a[u] = 1 4 | while len(q) > 0 : 5 | x = q.pop() 6 | if x == v : return False 7 | for i in ke[x] : 8 | if a[i] == 0 and i != k : 9 | q.append(i) 10 | a[i] = 1 11 | return True 12 | 13 | for t in range(int(input())) : 14 | n, m, u, v = [int(x) for x in input().split()] 15 | ke = [] 16 | for i in range(n + 1) : ke.append([]) 17 | for i in range(m) : 18 | x, y = [int(x) for x in input().split()] 19 | ke[x].append(y) 20 | ans = 0 21 | for i in range(1, n + 1) : 22 | if i != u and i != v : 23 | if check(n, i, u, v, ke) : ans += 1 24 | print(ans) 25 | -------------------------------------------------------------------------------- /PYKT059 - THÀNH PHẦN LIÊN THÔNG: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, m, k = [int(x) for x in input().split()] 4 | a = [] 5 | for i in range(n + 1): 6 | a.append([]) 7 | b = [0] * (n + 1) 8 | for i in range(m) : 9 | x, y = [int(x) for x in input().split()] 10 | a[x].append(y) 11 | a[y].append(x) 12 | q = [] 13 | q.append(k) 14 | b[k] = 1 15 | while len(q) > 0 : 16 | x = q.pop() 17 | for i in a[x] : 18 | if b[i] == 0 : 19 | q.append(i) 20 | b[i] = 1 21 | for i in range(1, n + 1) : 22 | if b[i] == 0 : 23 | print(i) 24 | -------------------------------------------------------------------------------- /PYKT067 - HOÁN VỊ NGƯỢC: -------------------------------------------------------------------------------- 1 | d = [0] * 15 2 | n = 0 3 | def Try(s) : 4 | if len(s) == n : 5 | print(s, end = ' ') 6 | return 7 | for i in range(n, 0, -1) : 8 | if d[i] == 0 : 9 | d[i] = 1 10 | Try(s + str(i)) 11 | d[i] = 0 12 | 13 | t = int(input()) 14 | for i in range(t) : 15 | n = int(input()) 16 | s = 1 17 | for i in range(n) : s *= i + 1 18 | print(s) 19 | Try('') 20 | print() 21 | 22 | ''' Do Xuan Huong 23 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 27 | @@@@@@@@@@##########################################@@@@@@@@@ 28 | @@@@@@@@##############################################@@@@@@@ 29 | @@@@@@#################################################@@@@@@ 30 | @@@@@####################################################@@@@ 31 | @@@%#####################@@@@@@@@@@@######################@@@ 32 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 33 | @@##################@@@@@@ @@@@@@##################@@ 34 | @@#################@@@@@ @@@@###################@ 35 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 36 | @ &@@@@ @@@@ .......@@ 37 | @@ @@@@@@ @@@@@@ .......@@ 38 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 39 | @@@ @@@@@@@@@@@ ......@@@@ 40 | @@@@ ......@@@@@ 41 | @@@@@@ ......@@@@@@ 42 | @@@@@@@ .....@@@@@@@@ 43 | @@@@@@@@@ .....@@@@@@@@@@ 44 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 48 | ''' 49 | -------------------------------------------------------------------------------- /PYKT068 - DANH SÁCH MÔN THI: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | m = {} 3 | for i in range(n) : 4 | ma = input() 5 | ten = input() 6 | ht = input() 7 | m[ma] = [ten, ht] 8 | for i in sorted(m) : 9 | print(i, m[i][0], m[i][1]) 10 | 11 | ''' Do Xuan Huong 12 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 13 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 14 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 16 | @@@@@@@@@@##########################################@@@@@@@@@ 17 | @@@@@@@@##############################################@@@@@@@ 18 | @@@@@@#################################################@@@@@@ 19 | @@@@@####################################################@@@@ 20 | @@@%#####################@@@@@@@@@@@######################@@@ 21 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 22 | @@##################@@@@@@ @@@@@@##################@@ 23 | @@#################@@@@@ @@@@###################@ 24 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 25 | @ &@@@@ @@@@ .......@@ 26 | @@ @@@@@@ @@@@@@ .......@@ 27 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 28 | @@@ @@@@@@@@@@@ ......@@@@ 29 | @@@@ ......@@@@@ 30 | @@@@@@ ......@@@@@@ 31 | @@@@@@@ .....@@@@@@@@ 32 | @@@@@@@@@ .....@@@@@@@@@@ 33 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 34 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 35 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 37 | ''' 38 | -------------------------------------------------------------------------------- /PYKT072 - XOAY VÒNG XÂU KÝ TỰ: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = [''] * n 3 | for i in range(n) : 4 | a[i] = input() 5 | s = a[0] 6 | m, ok, ans = len(s), 1, 10**9 7 | for i in range(m) : 8 | d = 0 9 | for j in range(n) : 10 | x = a[j] 11 | for k in range(m) : 12 | if x == s : 13 | d += k 14 | break 15 | x = x[1::] + x[0] 16 | if x != s : ok = 0 17 | ans = min(ans, d) 18 | s = s[1::] + s[0] 19 | if ok == 0 : print(-1) 20 | else : print(ans) 21 | 22 | ''' Do Xuan Huong 23 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 27 | @@@@@@@@@@##########################################@@@@@@@@@ 28 | @@@@@@@@##############################################@@@@@@@ 29 | @@@@@@#################################################@@@@@@ 30 | @@@@@####################################################@@@@ 31 | @@@%#####################@@@@@@@@@@@######################@@@ 32 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 33 | @@##################@@@@@@ @@@@@@##################@@ 34 | @@#################@@@@@ @@@@###################@ 35 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 36 | @ &@@@@ @@@@ .......@@ 37 | @@ @@@@@@ @@@@@@ .......@@ 38 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 39 | @@@ @@@@@@@@@@@ ......@@@@ 40 | @@@@ ......@@@@@ 41 | @@@@@@ ......@@@@@@ 42 | @@@@@@@ .....@@@@@@@@ 43 | @@@@@@@@@ .....@@@@@@@@@@ 44 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 48 | ''' 49 | -------------------------------------------------------------------------------- /PYKT073 - XÁC ĐỊNH THỂ LOẠI THƠ: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | ok, k, a = 0, [], [] 3 | for i in range(n): 4 | s = input().split() 5 | if len(a) == 0 and len(s) == 6 : k.append(1) 6 | a.append(s) 7 | if len(a) > 1 and len(s) == 6 and len(a[-2]) == 7 : k.append(1) 8 | if len(s) == 7 : ok += 1 9 | if ok == 4: 10 | k.append(2) 11 | ok = 0 12 | 13 | print(len(k)) 14 | for i in k: 15 | print(i) 16 | 17 | ''' Do Xuan Huong 18 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 19 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 22 | @@@@@@@@@@##########################################@@@@@@@@@ 23 | @@@@@@@@##############################################@@@@@@@ 24 | @@@@@@#################################################@@@@@@ 25 | @@@@@####################################################@@@@ 26 | @@@%#####################@@@@@@@@@@@######################@@@ 27 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 28 | @@##################@@@@@@ @@@@@@##################@@ 29 | @@#################@@@@@ @@@@###################@ 30 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 31 | @ &@@@@ @@@@ .......@@ 32 | @@ @@@@@@ @@@@@@ .......@@ 33 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 34 | @@@ @@@@@@@@@@@ ......@@@@ 35 | @@@@ ......@@@@@ 36 | @@@@@@ ......@@@@@@ 37 | @@@@@@@ .....@@@@@@@@ 38 | @@@@@@@@@ .....@@@@@@@@@@ 39 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 40 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 43 | ''' 44 | -------------------------------------------------------------------------------- /PYKT074 - GỬI THÔNG BÁO: -------------------------------------------------------------------------------- 1 | import textwrap 2 | 3 | t = int(input()) 4 | for i in range(t) : 5 | print(textwrap.shorten(input(), width = 100, placeholder = '')) 6 | 7 | ''' Do Xuan Huong 8 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 9 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 10 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 11 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 12 | @@@@@@@@@@##########################################@@@@@@@@@ 13 | @@@@@@@@##############################################@@@@@@@ 14 | @@@@@@#################################################@@@@@@ 15 | @@@@@####################################################@@@@ 16 | @@@%#####################@@@@@@@@@@@######################@@@ 17 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 18 | @@##################@@@@@@ @@@@@@##################@@ 19 | @@#################@@@@@ @@@@###################@ 20 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 21 | @ &@@@@ @@@@ .......@@ 22 | @@ @@@@@@ @@@@@@ .......@@ 23 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 24 | @@@ @@@@@@@@@@@ ......@@@@ 25 | @@@@ ......@@@@@ 26 | @@@@@@ ......@@@@@@ 27 | @@@@@@@ .....@@@@@@@@ 28 | @@@@@@@@@ .....@@@@@@@@@@ 29 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 32 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 33 | ''' 34 | -------------------------------------------------------------------------------- /PYKT075 - SAO CHÉP DANH BẠ: -------------------------------------------------------------------------------- 1 | class DT : 2 | def __init__(self, ten, sdt, ngay) : 3 | self.ten = ten 4 | self.sdt = sdt 5 | self.ngay = ngay 6 | self.x = ten.split()[-1] 7 | def getstr(self) : 8 | return self.ten + ': ' + self.sdt + ' ' + self.ngay 9 | ip = open('SOTAY.txt', 'r') 10 | inp = ip.read().split('\n') 11 | a = [] 12 | while len(inp) > 0 : 13 | x = inp[0] 14 | inp.pop(0) 15 | if x[:4:] == 'Ngay' : ngay = x[5::] 16 | elif len(inp) > 0 : 17 | sdt = inp[0] 18 | inp.pop(0) 19 | a.append(DT(x, sdt, ngay)) 20 | a = sorted(a, key = lambda x : (x.x, x.ten)) 21 | ip.close() 22 | ot = open('DIENTHOAI.txt', 'w') 23 | for i in a : ot.write(i.getstr() + '\n') 24 | ot.close() 25 | -------------------------------------------------------------------------------- /PYKT076 - DANH SÁCH PHIM: -------------------------------------------------------------------------------- 1 | class Phim : 2 | def __init__(self, ma, theloai, tg, ten, sotap) : 3 | self.ma = 'P{:03d}'.format(ma) 4 | self.theloai = theloai 5 | self.ten = ten 6 | self.tg = tg 7 | self.ngay = int(tg[:2:]) 8 | self.thang = int(tg[3:5:]) 9 | self.nam = int(tg[6::]) 10 | self.sotap = sotap 11 | def __str__(self) : 12 | return self.ma + ' ' + self.theloai+ ' ' + self.tg + ' ' + self.ten + ' ' + str(self.sotap) 13 | 14 | n, m = [int(x) for x in input().split()] 15 | tl = [] 16 | p = [] 17 | for i in range(n) : tl.append(input()) 18 | for i in range(m) : 19 | ma = input() 20 | ngay = input() 21 | ten = input() 22 | sotap = int(input()) 23 | p.append(Phim(i + 1, tl[int(ma[2::]) - 1], ngay, ten, sotap)) 24 | p = sorted(p, key = lambda x : (x.nam, x.thang, x.ngay, x.ten, -x.sotap)) 25 | for i in range(m) : 26 | print(p[i]) 27 | 28 | ''' Do Xuan Huong 29 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 32 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 33 | @@@@@@@@@@##########################################@@@@@@@@@ 34 | @@@@@@@@##############################################@@@@@@@ 35 | @@@@@@#################################################@@@@@@ 36 | @@@@@####################################################@@@@ 37 | @@@%#####################@@@@@@@@@@@######################@@@ 38 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 39 | @@##################@@@@@@ @@@@@@##################@@ 40 | @@#################@@@@@ @@@@###################@ 41 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 42 | @ &@@@@ @@@@ .......@@ 43 | @@ @@@@@@ @@@@@@ .......@@ 44 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 45 | @@@ @@@@@@@@@@@ ......@@@@ 46 | @@@@ ......@@@@@ 47 | @@@@@@ ......@@@@@@ 48 | @@@@@@@ .....@@@@@@@@ 49 | @@@@@@@@@ .....@@@@@@@@@@ 50 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 52 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 53 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 54 | ''' 55 | -------------------------------------------------------------------------------- /PYKT077 - LỊCH THI HỌC KỲ: -------------------------------------------------------------------------------- 1 | class Mon : 2 | def __init__(self, maca, mamon, ten, ngaythi, giothi, nhom) : 3 | self.maca = 'T{:03d}'.format(maca) 4 | self.mamon = mamon 5 | self.ten = ten 6 | self.ngaythi = ngaythi 7 | self.ngay = int(ngaythi[:2:]) 8 | self.thang = int(ngaythi[3:5:]) 9 | self.nam = int(ngaythi[6::]) 10 | self.giothi = giothi 11 | self.gio = int(giothi[:2:]) 12 | self.phut = int(giothi[3::]) 13 | self.nhom = nhom 14 | 15 | m = {} 16 | n, k = [int(x) for x in input().split()] 17 | for i in range(n) : 18 | ma = input() 19 | mon = input() 20 | m[ma] = mon 21 | a = [] 22 | for i in range(k) : 23 | ma, ngay, gio, nhom = input().split() 24 | a.append(Mon(i + 1, ma, m[ma], ngay, gio, nhom)) 25 | a = sorted(a, key = lambda x : (x.nam, x.thang, x.ngay, x.gio, x.phut, x.mamon)) 26 | for i in a : 27 | print(i.maca, i.mamon, i.ten, i.ngaythi, i.giothi, i.nhom) 28 | -------------------------------------------------------------------------------- /PYKT078 - SẮP XẾP DÃY SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n, k = [int(x) for x in input().split()] 6 | a = [int(x) for x in input().split()] 7 | b = [] 8 | c = [] 9 | Max = max(a) 10 | for i in range(n) : 11 | if a[i] == Max : 12 | a.insert(i, k) 13 | break 14 | for i in a : 15 | if i < 0 : b.append(i) 16 | else : c.append(i) 17 | for i in b : print(i, end = " ") 18 | for i in c : print(i, end = " ") 19 | print() 20 | -------------------------------------------------------------------------------- /PYKT079 - ĐIỀN SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | t = int(input()) 4 | for z in range(t) : 5 | n = int(input()) 6 | m = {} 7 | s = 0 8 | a = [int(x) for x in input().split()] 9 | for i in a : 10 | m[i] = 1 11 | Min = min(a) 12 | Max = max(a) 13 | for i in range(Min, Max) : 14 | if not(i in m) : s += 1 15 | print(s) 16 | -------------------------------------------------------------------------------- /PYKT080 - THỐNG KÊ DỊCH TỄ: -------------------------------------------------------------------------------- 1 | n, m = [int(x) for x in input().split()] 2 | s = 0 3 | a, q, b = [[0]] * n, [], [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] 4 | for i in range(n): 5 | a[i] = [int(x) for x in input().split()] 6 | for j in range(m): 7 | if a[i][j] == -1: 8 | q.append([i,j]) 9 | while len(q) > 0: 10 | u = q[0] 11 | q.pop(0) 12 | for i in b: 13 | x, y = i[0] + u[0], i[1] + u[1] 14 | if x >= 0 and x < n and y >= 0 and y < m: 15 | if a[x][y] != 0: 16 | s += a[x][y] 17 | a[x][y] = 0 18 | print(s) 19 | 20 | ''' Do Xuan Huong 21 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 25 | @@@@@@@@@@##########################################@@@@@@@@@ 26 | @@@@@@@@##############################################@@@@@@@ 27 | @@@@@@#################################################@@@@@@ 28 | @@@@@####################################################@@@@ 29 | @@@%#####################@@@@@@@@@@@######################@@@ 30 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 31 | @@##################@@@@@@ @@@@@@##################@@ 32 | @@#################@@@@@ @@@@###################@ 33 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 34 | @ &@@@@ @@@@ .......@@ 35 | @@ @@@@@@ @@@@@@ .......@@ 36 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 37 | @@@ @@@@@@@@@@@ ......@@@@ 38 | @@@@ ......@@@@@ 39 | @@@@@@ ......@@@@@@ 40 | @@@@@@@ .....@@@@@@@@ 41 | @@@@@@@@@ .....@@@@@@@@@@ 42 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 46 | ''' 47 | -------------------------------------------------------------------------------- /PYKT081 - ĐỊA CHỈ IP: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def check(s) : 4 | if len(s) < 4 : return 0 5 | for i in s : 6 | if i.isdigit() : 7 | if int(i) < 0 or int(i) > 255 : return 0 8 | else : return 0 9 | return 1 10 | 11 | t = int(input()) 12 | for z in range(t) : 13 | a = input().split('.') 14 | if check(a) == 1 : print("YES") 15 | else : print("NO") 16 | -------------------------------------------------------------------------------- /PYKT082 - TÍNH ĐIỂM THI IELTS: -------------------------------------------------------------------------------- 1 | def trans(x): 2 | if x >=3 and x <=4 : return 2.5 3 | if x >=5 and x <=6 : return 3.0 4 | if x >=7 and x <=9 : return 3.5 5 | if x >=10 and x <=12 : return 4.0 6 | if x >=13 and x <=15 : return 4.5 7 | if x >=16 and x <=19 : return 5.0 8 | if x >=20 and x <=22 : return 5.5 9 | if x >=23 and x <=26 : return 6.0 10 | if x >=27 and x <=29 : return 6.5 11 | if x >=30 and x <=32 : return 7.0 12 | if x >=33 and x <=34 : return 7.5 13 | if x >=35 and x <=36 : return 8.0 14 | if x >=37 and x <=38 : return 8.5 15 | if x >=39 and x <=40 : return 9.0 16 | 17 | t = int(input()) 18 | for i in range(t): 19 | a = input().split() 20 | r, l = int(a[0]), int(a[1]) 21 | s, w = float(a[2]), float(a[3]) 22 | x = (trans(r) + trans(l) + s + w) / 4.0 23 | if x - int(x) >= 0.75 : print(int(x) + 1.0) 24 | elif x - int(x) >= 0.25 : print(int(x) + 0.5) 25 | else: print(int(x)) 26 | 27 | ''' Do Xuan Huong 28 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 32 | @@@@@@@@@@##########################################@@@@@@@@@ 33 | @@@@@@@@##############################################@@@@@@@ 34 | @@@@@@#################################################@@@@@@ 35 | @@@@@####################################################@@@@ 36 | @@@%#####################@@@@@@@@@@@######################@@@ 37 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 38 | @@##################@@@@@@ @@@@@@##################@@ 39 | @@#################@@@@@ @@@@###################@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 41 | @ &@@@@ @@@@ .......@@ 42 | @@ @@@@@@ @@@@@@ .......@@ 43 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 44 | @@@ @@@@@@@@@@@ ......@@@@ 45 | @@@@ ......@@@@@ 46 | @@@@@@ ......@@@@@@ 47 | @@@@@@@ .....@@@@@@@@ 48 | @@@@@@@@@ .....@@@@@@@@@@ 49 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 52 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 53 | ''' 54 | -------------------------------------------------------------------------------- /PYKT083 - THU PHÍ XE Ô TÔ: -------------------------------------------------------------------------------- 1 | def cnt(s, d): 2 | if s == 'Xe_con' : 3 | if d == '5' : return 10000 4 | else : return 15000 5 | if s == 'Xe_tai' : return 20000 6 | if s == 'Xe_khach' : 7 | if d == '29' : return 50000 8 | else : return 70000 9 | 10 | n = int(input()) 11 | m = {} 12 | for i in range(n): 13 | a = input().split() 14 | if a[3] == 'IN': 15 | if a[4] not in m: 16 | m[a[4]] = cnt(a[1], a[2]) 17 | else: 18 | m[a[4]] += cnt(a[1], a[2]) 19 | m = sorted(m.items(), key = lambda x: x[0]) 20 | for i in m: 21 | print(str(i[0]) + ':', i[1]) 22 | 23 | ''' Do Xuan Huong 24 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 26 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 27 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 28 | @@@@@@@@@@##########################################@@@@@@@@@ 29 | @@@@@@@@##############################################@@@@@@@ 30 | @@@@@@#################################################@@@@@@ 31 | @@@@@####################################################@@@@ 32 | @@@%#####################@@@@@@@@@@@######################@@@ 33 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 34 | @@##################@@@@@@ @@@@@@##################@@ 35 | @@#################@@@@@ @@@@###################@ 36 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 37 | @ &@@@@ @@@@ .......@@ 38 | @@ @@@@@@ @@@@@@ .......@@ 39 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 40 | @@@ @@@@@@@@@@@ ......@@@@ 41 | @@@@ ......@@@@@ 42 | @@@@@@ ......@@@@@@ 43 | @@@@@@@ .....@@@@@@@@ 44 | @@@@@@@@@ .....@@@@@@@@@@ 45 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 47 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 48 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 49 | ''' 50 | -------------------------------------------------------------------------------- /PYKT084 - CÂU HỎI THEO CHỦ ĐỀ - 1: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = [] 3 | s = '' 4 | for i in range(n) : 5 | s = input() 6 | a.append(s) 7 | if s == '' : 8 | n += 1 9 | print(a[0] + ':', len(a) - 2) 10 | a.clear() 11 | print(a[0] + ':', len(a) - 1) 12 | 13 | ''' Do Xuan Huong 14 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 18 | @@@@@@@@@@##########################################@@@@@@@@@ 19 | @@@@@@@@##############################################@@@@@@@ 20 | @@@@@@#################################################@@@@@@ 21 | @@@@@####################################################@@@@ 22 | @@@%#####################@@@@@@@@@@@######################@@@ 23 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 24 | @@##################@@@@@@ @@@@@@##################@@ 25 | @@#################@@@@@ @@@@###################@ 26 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 27 | @ &@@@@ @@@@ .......@@ 28 | @@ @@@@@@ @@@@@@ .......@@ 29 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 30 | @@@ @@@@@@@@@@@ ......@@@@ 31 | @@@@ ......@@@@@ 32 | @@@@@@ ......@@@@@@ 33 | @@@@@@@ .....@@@@@@@@ 34 | @@@@@@@@@ .....@@@@@@@@@@ 35 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 39 | ''' 40 | -------------------------------------------------------------------------------- /PYKT085 - CÂU HỎI THEO CHỦ ĐỀ - 2: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | a = [] 3 | s = '' 4 | for i in range(n) : 5 | s = input() 6 | a.append(s) 7 | if s == '' : 8 | n += 1 9 | print(a[0] + ':', len(a) - 2) 10 | a.clear() 11 | print(a[0] + ':', len(a) - 1) 12 | 13 | ''' Do Xuan Huong 14 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 18 | @@@@@@@@@@##########################################@@@@@@@@@ 19 | @@@@@@@@##############################################@@@@@@@ 20 | @@@@@@#################################################@@@@@@ 21 | @@@@@####################################################@@@@ 22 | @@@%#####################@@@@@@@@@@@######################@@@ 23 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 24 | @@##################@@@@@@ @@@@@@##################@@ 25 | @@#################@@@@@ @@@@###################@ 26 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 27 | @ &@@@@ @@@@ .......@@ 28 | @@ @@@@@@ @@@@@@ .......@@ 29 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 30 | @@@ @@@@@@@@@@@ ......@@@@ 31 | @@@@ ......@@@@@ 32 | @@@@@@ ......@@@@@@ 33 | @@@@@@@ .....@@@@@@@@ 34 | @@@@@@@@@ .....@@@@@@@@@@ 35 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 39 | ''' 40 | -------------------------------------------------------------------------------- /PYKT086 - CHUYỂN ĐỔI NHỊ PHÂN: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | file = open('DATA.in', 'r') 4 | f = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'] 5 | t = int(file.readline()) 6 | for i in range(t) : 7 | n = int(file.readline()) 8 | a = file.readline().rstrip('\n') 9 | n = int(math.log(n)/math.log(2)) 10 | while len(a) % n != 0 : a = '0' + a 11 | for i in range(0, len(a), n) : 12 | s = 0 13 | for j in range(i, i + n): 14 | if a[j] == '1' : s += pow(2, n - j + i - 1) 15 | print(f[s],end = "") 16 | print() 17 | 18 | ''' Do Xuan Huong 19 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 20 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 21 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 23 | @@@@@@@@@@##########################################@@@@@@@@@ 24 | @@@@@@@@##############################################@@@@@@@ 25 | @@@@@@#################################################@@@@@@ 26 | @@@@@####################################################@@@@ 27 | @@@%#####################@@@@@@@@@@@######################@@@ 28 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 29 | @@##################@@@@@@ @@@@@@##################@@ 30 | @@#################@@@@@ @@@@###################@ 31 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 32 | @ &@@@@ @@@@ .......@@ 33 | @@ @@@@@@ @@@@@@ .......@@ 34 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 35 | @@@ @@@@@@@@@@@ ......@@@@ 36 | @@@@ ......@@@@@ 37 | @@@@@@ ......@@@@@@ 38 | @@@@@@@ .....@@@@@@@@ 39 | @@@@@@@@@ .....@@@@@@@@@@ 40 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 41 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 42 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 44 | ''' 45 | -------------------------------------------------------------------------------- /PYKT087 - SỐ ĐẶC BIỆT: -------------------------------------------------------------------------------- 1 | mod = 1000000007 2 | 3 | def pow(a, b) : 4 | if b == 0 : return 1 5 | x = pow(a, int(b / 2)) 6 | x = (x * x) % mod 7 | if b % 2 == 1 : x *= a 8 | return x % mod 9 | 10 | def cal(n, k) : 11 | if k <= 1 : return k 12 | x = 0 13 | while (k >> x) ^ 1 : x += 1 14 | return (pow(n, x) + cal(n, k ^ (1 << x))) % mod 15 | 16 | for t in range(int(input())) : 17 | n, k = [int(x) for x in input().split()] 18 | print(cal(n, k)) 19 | -------------------------------------------------------------------------------- /PYKT088 - SỐ CÓ 9 ƯỚC SỐ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | n, s, i = int(input()), 0, 2 4 | l = int(n ** (0.5)) 5 | a = [i for i in range(l + 1)] 6 | while i * i <= l : 7 | if a[i] == i : 8 | for j in range(i * i, l + 1, i): 9 | if a[j] == j : a[j] = i 10 | i += 1 11 | for i in range(2, l + 1) : 12 | p = a[i] 13 | q = a[i // a[i]] 14 | if p * q == i and q != 1 and p != q : s += 1 15 | elif a[i] == i : 16 | if i ** 8 <= n : s += 1 17 | print(s) 18 | -------------------------------------------------------------------------------- /PYKT089 - SẮP XẾP CHẴN LẺ: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | import functools 4 | 5 | def cmp(a, b) : 6 | if a < b : return 1 7 | else : return -1 8 | 9 | n = int(input()) 10 | a, b, c, d = [], [], [], [0] * n 11 | while True : 12 | x = [int(x) for x in input().split()] 13 | a += x 14 | if len(a) == n : break 15 | for i in range(n) : 16 | if a[i] % 2 == 1 : 17 | b.append(a[i]) 18 | d[i] = 1 19 | else : c.append(a[i]) 20 | b = sorted(b) 21 | c = sorted(c, key = functools.cmp_to_key(cmp)) 22 | for i in range(n) : 23 | if d[i] == 1 : 24 | print(b[-1], end = " ") 25 | b.pop() 26 | else : 27 | print(c[-1], end = " ") 28 | c.pop() 29 | -------------------------------------------------------------------------------- /PYKT090 - DANH SÁCH EMAIL: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | file = open('CONTACT.in', 'r') 4 | s = {} 5 | for x in file : 6 | if x[-1] == '\n' : 7 | x = x[:-1] 8 | s[x.lower()] = 1 9 | s = sorted(s.keys()) 10 | for x in s : 11 | print(x) 12 | 13 | ''' Do Xuan Huong 14 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 15 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 16 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 17 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 18 | @@@@@@@@@@##########################################@@@@@@@@@ 19 | @@@@@@@@##############################################@@@@@@@ 20 | @@@@@@#################################################@@@@@@ 21 | @@@@@####################################################@@@@ 22 | @@@%#####################@@@@@@@@@@@######################@@@ 23 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 24 | @@##################@@@@@@ @@@@@@##################@@ 25 | @@#################@@@@@ @@@@###################@ 26 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 27 | @ &@@@@ @@@@ .......@@ 28 | @@ @@@@@@ @@@@@@ .......@@ 29 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 30 | @@@ @@@@@@@@@@@ ......@@@@ 31 | @@@@ ......@@@@@ 32 | @@@@@@ ......@@@@@@ 33 | @@@@@@@ .....@@@@@@@@ 34 | @@@@@@@@@ .....@@@@@@@@@@ 35 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 36 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 37 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 38 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 39 | ''' 40 | -------------------------------------------------------------------------------- /PYKT091 - TÌM TỪ THUẬN NGHỊCH DÀI NHẤT: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | file = open('VANBAN.in', 'r') 4 | b = {} 5 | s = 0 6 | for x in file: 7 | a = x.split() 8 | for i in a : 9 | if i == i[::-1] : 10 | if len(i) > s : 11 | s = len(i) 12 | b.clear() 13 | b[i] = 1 14 | elif len(i) == s : 15 | if i not in b : b[i] = 1 16 | else : b[i] += 1 17 | for i in b : 18 | print(i, b[i]) 19 | 20 | ''' Do Xuan Huong 21 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 22 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 25 | @@@@@@@@@@##########################################@@@@@@@@@ 26 | @@@@@@@@##############################################@@@@@@@ 27 | @@@@@@#################################################@@@@@@ 28 | @@@@@####################################################@@@@ 29 | @@@%#####################@@@@@@@@@@@######################@@@ 30 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 31 | @@##################@@@@@@ @@@@@@##################@@ 32 | @@#################@@@@@ @@@@###################@ 33 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 34 | @ &@@@@ @@@@ .......@@ 35 | @@ @@@@@@ @@@@@@ .......@@ 36 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 37 | @@@ @@@@@@@@@@@ ......@@@@ 38 | @@@@ ......@@@@@ 39 | @@@@@@ ......@@@@@@ 40 | @@@@@@@ .....@@@@@@@@ 41 | @@@@@@@@@ .....@@@@@@@@@@ 42 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 43 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 46 | ''' 47 | -------------------------------------------------------------------------------- /PYKT093 - TÍNH ĐIỂM TRUNG BÌNH: -------------------------------------------------------------------------------- 1 | from math import ceil 2 | 3 | class SV: 4 | def __init__(self, ma, ten, d): 5 | self.ma = 'SV{:02d}'.format(ma) 6 | self.ten = self.rename(ten) 7 | self.d = d 8 | 9 | def rename(self, ten) -> str: 10 | return ' '.join(i.title() for i in ten.strip().split()) 11 | 12 | def __str__(self) -> str: 13 | return '{:s} {:s} {:.2f} {:d}'.format(self.ma, self.ten, ceil(self.d * 100) / 100, self.rank) 14 | 15 | a = [] 16 | for i in range(int(input())): 17 | a.append(SV(i + 1, input(), (3 * int(input()) + 3 * int(input()) + 2 * int(input())) / 8)) 18 | a = sorted(a, key = lambda x: (-x.d, x.ma)) 19 | a[0].rank = 1 20 | for i in range(1, len(a)): 21 | a[i].rank = a[i-1].rank if a[i].d == a[i-1].d else i + 1 22 | print(*a, sep = '\n') 23 | -------------------------------------------------------------------------------- /PYKT096 - DANH SÁCH THI LẬP TRÌNH: -------------------------------------------------------------------------------- 1 | class SV : 2 | def __init__(self, ma, ten, team, tr) : 3 | self.ma = 'C{:03d}'.format(ma) 4 | self.ten = ten 5 | self.team = team 6 | self.tr = tr 7 | 8 | n = int(input()) 9 | t = [1] 10 | for i in range(n) : 11 | t.append([input(), input()]) 12 | n = int(input()) 13 | a = [] 14 | for i in range(n) : 15 | ten = input() 16 | team = input() 17 | a.append(SV(i + 1, ten, t[int(team[4::])][0], t[int(team[4::])][1])) 18 | a = sorted(a, key = lambda x : x.ten) 19 | for i in a : 20 | print(i.ma, i.ten, i.team, i.tr) 21 | -------------------------------------------------------------------------------- /PYKT098 - LOẠI BỎ SỐ NGUYÊN: -------------------------------------------------------------------------------- 1 | # Lazygarde 2 | 3 | def check(s) : 4 | k = 0 5 | for i in s : 6 | if not i.isdigit() : 7 | return True 8 | k = k * 10 + int(i) 9 | if k <= 2147483647 and k >= -2147483648 : 10 | return False 11 | return True 12 | 13 | file = open('DATA.in', 'r') 14 | a = [] 15 | for line in file: 16 | for i in line.split(): 17 | if check(i) : a.append(i) 18 | for i in sorted(a) : 19 | print(i, end = ' ') 20 | 21 | ''' Do Xuan Huong 22 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 23 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 24 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 25 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 26 | @@@@@@@@@@##########################################@@@@@@@@@ 27 | @@@@@@@@##############################################@@@@@@@ 28 | @@@@@@#################################################@@@@@@ 29 | @@@@@####################################################@@@@ 30 | @@@%#####################@@@@@@@@@@@######################@@@ 31 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 32 | @@##################@@@@@@ @@@@@@##################@@ 33 | @@#################@@@@@ @@@@###################@ 34 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 35 | @ &@@@@ @@@@ .......@@ 36 | @@ @@@@@@ @@@@@@ .......@@ 37 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 38 | @@@ @@@@@@@@@@@ ......@@@@ 39 | @@@@ ......@@@@@ 40 | @@@@@@ ......@@@@@@ 41 | @@@@@@@ .....@@@@@@@@ 42 | @@@@@@@@@ .....@@@@@@@@@@ 43 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 44 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 45 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 46 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 47 | ''' 48 | -------------------------------------------------------------------------------- /PYKT2049 - BÌNH THÔNG NHAU: -------------------------------------------------------------------------------- 1 | par = [0] * 10004 2 | rankz = [0] * 10004 3 | 4 | def init() : 5 | for i in range(10004) : 6 | par[i] = i 7 | rankz[i] = 1 8 | 9 | def find(u) : 10 | if par[u] != u : par[u] = find(par[u]) 11 | return par[u] 12 | 13 | def join(u, v) : 14 | u = find(u) 15 | v = find(v) 16 | if u == v : return 17 | if rankz[u] == rankz[v] : rankz[u] += 1 18 | if rankz[u] < rankz[v] : par[u] = v 19 | else : par[v] = u 20 | 21 | init() 22 | q = int(input()) 23 | for i in range(q) : 24 | u, v, t = map(int, input().split()) 25 | if t == 1 : join(u, v) 26 | 27 | else : 28 | u = find(u) 29 | v = find(v) 30 | if u == v : print("1") 31 | else : print("0") 32 | --------------------------------------------------------------------------------