#include<bits/stdc++.h> usingnamespace std; voidsolve(int t){ while (t--) { string p, cmp; cin >> p >> cmp; int i = 0, j = 0; bool flag = true; // 使用 && 只在两个字符串都有字符时进入循环 while (i < p.length() && j < cmp.length()) { int li = i, lj = j;
while (i < p.length() && p[i] == p[li]) ++i; while (j < cmp.length() && cmp[j] == cmp[lj]) ++j; // 检查当前两组字符是否一致(字符必须相同) if (p[li] != cmp[lj]) { flag = false; break; } int cnt_p = i - li, cnt_cmp = j - lj; // 检查 cmp 的数量是否在合法范围内 if (cnt_cmp < cnt_p || cnt_cmp > 2 * cnt_p) { flag = false; break; } } // 遍历结束后,如果两字符串未同时结束则说明不匹配 if (i != p.length() || j != cmp.length()) { flag = false; } cout << (flag ? "YES" : "NO") << '\n'; } } intmain(){ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define int long long constint MAX_BITS = 31; int t, n;
// 正解 voidsolve(){ cin >> n; vector<int> a(n); for (auto &x : a) cin >> x;
// 统计每一位上有多少个 1 vector<int> bitCount(MAX_BITS, 0); for (int i = 0; i < n; ++i) { for (int b = 0; b < MAX_BITS; ++b) { if ((a[i] >> b) & 1) { bitCount[b]++; } } }
int ans = 0; for (int i = 0; i < n; ++i) { int total = 0; for (int b = 0; b < MAX_BITS; ++b) { int cnt1 = bitCount[b]; int cnt0 = n - cnt1; if ((a[i] >> b) & 1) { // 当前数该位为 1,与 cnt0 个 0 异或为 1 total += cnt0 * (1LL << b); } else { // 当前数该位为 0,与 cnt1 个 1 异或为 1 total += cnt1 * (1LL << b); } } ans = max(ans, total); }
cout << ans << '\n'; }
// 暴力 voidsolve1(){ cin >> n; vector<int> a(n); for (auto &x : a) cin >> x;
int res = 0; for (int i = 0; i < n; ++i) { int cur = 0; for (int j = 0; j < n; ++j) { cur += (a[i] ^ a[j]); } res = max(res, cur); } cout << res << '\n'; }
int32_tmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> t; while (t--) solve(); }