1 条题解
-
0
这道题可以通过异或的方式来写,根据异或^=的性质a^a=0;a^0=a,(a^b=c,c^b=a)下面是代码
#include <bits/stdc++.h> using namespace std; int main() { string s = "ZWPXBXSWQCZZLX"; string s1, single, doub; char diff1 = 0, diff2 = 0; int k; cin >> k; for (int i = 0; i < s.size(); i++) { if (i % 2 == 0) { doub += s[i]; diff1 ^= s[i]; } else { single += s[i]; diff2 ^= s[i]; } } for (int j = 0; j < k; j++) { cin >> s1; char diff11 = diff1, diff22 = diff2; for (int i = 0; i < s1.size(); i++) { if (i % 2 == 0) { diff11 ^= s1[i]; } else { diff22 ^= s1[i]; } } if (diff11 == 0 && diff22 == 0) { cout << "YES" << endl; } else { cout << "NO" << endl; } } return 0; }
- 1
信息
- ID
- 448
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 112
- 已通过
- 11
- 上传者