输入描述:
一个ASCII字符串,该字符串没有顺序,字符可以重复,输入字符串的长度<=30。
输出描述:
一个新的字符串,该字符串中字符在输入字符串中只出现一次,且该新字符串按照ASCII码从小到大的顺序排列。如果输入字符串中字符出现的次数都是大于1,则无需输出。
示例1:
输入:efghabcd1234efgh
输出:1234abcd
贴一下自己的代码,仅供参考,不一定准确。
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
string test1(string Input)
{
int hashmap[128] = {0};
string res;
for(int i = 0; i < Input.length(); ++i)
{
hashmap[static_cast<int>(Input[i])]++;
}
for(int i = 0; i < 128; ++i)
{
if(hashmap[i] == 1)
{
res += static_cast<char>(i);
}
}
return res;
}
string test2(string Input)
{
int hashmap[128] = {0};
string res;
for(int i = 0; i < Input.length(); ++i)
{
hashmap[Input[i] - '0']++;
}
for(int i = 0; i < 128; ++i)
{
if(hashmap[i] == 1)
{
res += i + '0';
}
}
return res;
}
};
int main()
{
char temp;
string Input;
Solution MySolution;
cin >> Input;
cout << MySolution.test1(Input) << endl;
cout << MySolution.test2(Input) << endl;
return 0;
}