C++ 查找字符串中第一个只出现一次的字符
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
string s;
cin >> s;
unordered_map<char, int> count;
for (char c : s) {
count[c]++;
}
for (char c : s) {
if (count[c] == 1) {
cout << c << endl;
return 0;
}
}
cout << 'no' << endl;
return 0;
}
原文地址: http://www.cveoy.top/t/topic/cFo1 著作权归作者所有。请勿转载和采集!