Computer >> Máy Tính >  >> Lập trình >> Python

Chương trình Python để kiểm tra xem hai danh sách có giống nhau về mặt hình tròn hay không

Đây là hai danh sách được đưa ra. Nhiệm vụ của chúng tôi là kiểm tra thời tiết và nhận thấy hai danh sách đã cho có giống nhau về mặt hình tròn hay không.

Ví dụ

Input : A = [100, 100, 10, 10, 100]
        B = [100, 100, 100, 10, 10]
Output : True

Giải thích

Đúng như khi các phần tử này trong danh sách sẽ xoay tròn thì chúng sẽ tương tự như các phần tử đã cho khác

Thuật toán

Step 1: Create First and Second List.
Step 2: Then Lists are converted to map.
Step 3: join () method is used for converting the list objects into the string.
Step 3: doubling list A and converted to the map.
Step 4: compare two list. If result is true then Two Lists are circularly identical and if return false then they are circularly non identical.

Mã mẫu

# Python program to check and verify whether two lists are circularly identical or not

A=list()
n=int(input("Enter the size of the First List ::"))
print("Enter the Element of First List ::")
for i in range(int(n)):
   k=int(input(""))
   A.append(k)

B=list()
n1=int(input("Enter the size of the Second List ::"))
print("Enter the Element of the Second List ::")
for i in range(int(n1)):
   k=int(input(""))
   B.append(k)

C=list()
n3=int(input("Enter the size of the Third List ::"))
print("Enter the Element of the Third List ::")
for i in range(int(n3)):
   k=int(input(""))
   C.append(k)

print("Compare First List and Second List ::>")
print(' '.join(map(str, B)) in ' '.join(map(str, A * 2)))
print("Compare Second List and Third List ::>")
print(' '.join(map(str, C)) in ' '.join(map(str, A * 2)))

Đầu ra

Enter the size of the First List :: 5
Enter the Element of First  List ::
10
10
0
0
10
Enter the size of the Second List :: 5
Enter the Element of the Second List ::
10
10
10
0
0
Enter the size of the Third List :: 5
Enter the Element of the Third List ::
1
10
10
0
0
Compare First List and Second List ::>
True
Compare Second List and Third List ::>
False