问题描述
编写一个程序,输入一组字符(只包含字母,且长度小于100,回车结束输入),该字符数组中只有一个字符出现的次数为奇数,其他字符出现的次数均为偶数,输出出现次数为奇数的字符。
#include <iostream>
#include <string>
#include <unordered_set>
using namespace std;
int main() {
string s;
cin >> s;
unordered_set<char> arr;
for (char c : s) {
auto it = arr.find(c);
if (it != arr.end()) {
arr.erase(it);
} else {
arr.insert(c);
}
}
for (char c : arr) {
cout << " " << c;
}
return 0;
}
典型的异或应用