作业题,写了Python才发现老师要我们写C++[捂脸],谢谢楼下各位。代码块:
def can_form_palindrome(s1, s2):
t = s1 + s2
count = {}
for char in t:
count[char] = count.get(char, 0) + 1
odd_count = sum(1 for k, v in count.items() if v % 2 != 0)
return odd_count <= 1
def check():
C = int(input())
for _ in range(C):
n, m = map(int, input().split())
s1 = input()
s2 = input()
if can_form_palindrome(s1, s2):
print("YES")
else:
print("NO")
check()