Here's one possible solution in Python:

# Read four integers from the user
a, b, c, d = map(int, input().split())

# Check if there are two matching pairs
if (a == b and c == d) or (a == c and b == d) or (a == d and b == c):
    print("two pairs")
else:
    print("not two pairs")

The map(int, input().split()) line reads a line of input from the user and splits it into a list of strings (using the default separator, which is whitespace). Then, the map(int, ...) function applies the int function to each string in the list, converting them to integers. Finally, the a, b, c, d = ... line unpacks the resulting four-element list into four separate variables.

The rest of the program checks if there are two matching pairs by testing all possible pairs of numbers. If any of them match, the program prints "two pairs". Otherwise, it prints "not two pairs".

Write a program that reads four integers and prints two pairs if the input consists of two matching pairs in some order and not two pairs otherwise For example 1 2 2 1 two pairs 1 2 2 3 not

原文地址: https://www.cveoy.top/t/topic/boSp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录