Cho ba chuỗi, cần xác định từng chuỗi là Pangram, Lipogram hay Pangrammatic Lipogram.
- Pangram: câu chứa mọi chữ cái trong bảng chữ cái ít nhất một lần.
- Lipogram: câu thiếu một hoặc nhiều chữ cái.
- Pangrammatic Lipogram: câu chứa tất cả chữ cái trừ đúng một chữ cái.
Ví dụ đầu vào và đầu ra:
pack my box with five dozen liquor jugs to stay in this mortal world or by my own hand go to oblivion, that is my conundrum. the quick brown fox jumps over a lazy dog waltz, nymph, for quick jigs ve bud Kết quả: The String is a Pangram The String isn't a Pangram but might be a Lipogram The String is a Pangram The String is a Pangrammatic Lipogram
Thuật toán
- Chuyển chuỗi về chữ thường.
- Đếm số chữ cái không xuất hiện trong chuỗi (biến i).
- Nếu i == 0 → Pangram.
- Nếu i == 1 → Pangrammatic Lipogram.
- Ngược lại → Không phải Pangram, có thể là Lipogram.
Ví dụ code
import string
def solve(input_string):
input_string = input_string.lower()
i = 0
for character in string.ascii_lowercase:
if input_string.find(character) < 0:
i += 1
if i == 0:
output = "The String is a Pangram"
elif i == 1:
output = "The String is a Pangrammatic Lipogram"
else:
output = "The String isn't a Pangram but might be a Lipogram"
return output
print(solve("pack my box with five dozen liquor jugs"))
print(solve("to stay in this mortal world or by my own hand go to oblivion,that is my conundrum."))
print(solve("the quick brown fox jumps over a lazy dog"))
print(solve("waltz, nymph, for quick jigs ve bud"))
Đầu vào
pack my box with five dozen liquor jugs to stay in this mortal world or by my own hand go to oblivion, that is my conundrum. the quick brown fox jumps over a lazy dog waltz, nymph, for quick jigs ve bud
Đầu ra
The String is a Pangram The String isn't a Pangram but might be a Lipogram The String is a Pangram The String is a Pangrammatic Lipogram