#include <iostream>
#include <string>using namespace std;int main()
{string temp = "";cout << "请输入字符串:";getline(cin,temp);string str = ""; //存放只出现一次的字符string str1 = ""; //存放重复的字符for (int i = 0; i < temp.length(); i++){string tempSub = temp.substr(i, 1); int b = temp.rfind(tempSub); //从后向前查找字符出现的位置if (i == b && str1.find(tempSub) == -1 && tempSub != " ") //如果b和遍历查找的位置一致,且str1 里没有该字符,说明只出现一次str +=temp.substr(i, 1);else if (str1.find(tempSub) == -1)str1 += temp.substr(i, 1);;}cout << "只出现一次的字符:" << str << endl;cout << "重复出现的字符的字符:" << str1 << endl;system("pause");return 0;
}