/-------找出两个字符数组中不同的字符-------------/
/*-------找出两个字符数组中不同的字符-------------*/
#include <iostream>
#include<map>
using namespace std;
int main()
{
char s[] = "abcd"; //找出两组字符串中不同的字符
char t[] = "abcde";
map<char, int> m;
for (size_t i = 0; i < sizeof(s)/sizeof(char)-1; i++) //将字符串s数值插入到容器k值中
{
m.insert(make_pair(s[i],i+1));
}
for (size_t i = 0; i < sizeof(t) / sizeof(char) - 1; i++)
{
auto it = m.find(t[i]); //利用find查找,如果迭代器到末尾,则字符t[i]中字符,为不同字符。
if (it==m.end())
{
cout << t[i] << ":为不同的字符"<<endl;
}
}
}
/-------统计字符串中出现的相同元素个数-------------/
/*-------统计字符串中出现的相同元素个数-------------*/
#include <iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
class Cmp //multimap降序排列重载函数
{
public:
bool operator()(int a,int b)const
{
return a