Python代码转C++求助(2)
  • 板块灌水区
  • 楼主Nostopathy
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/4/3 18:55
  • 上次更新2024/4/3 21:39:56
查看原帖
Python代码转C++求助(2)
1286053
Nostopathy楼主2024/4/3 18:55

作业题,写了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()
2024/4/3 18:55
加载中...