找出字符串中第一个只出现一次的字符
找出字符串中第一个只出现一次的字符(题面已经更新)
http://www.nowcoder.com/questionTerminal/e896d0f82f1246a3aa7b232ce38029d4
#include <iostream> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { for (int i = 0; i < str.size(); i++) { if (str.find_first_of(str[i]) == str.find_last_of(str[i])) { cout << str[i] << endl; break; } if (i == str.size()-1) cout << -1<<endl; } } return 0; }