先输入字典,查找有没有通过排列组合能够不重复的词,忽略大小写
采用vector<int> 安排26个位置放置字母个数,个数相同的则视为重复
再输出不重复的词
transform 泛型算法大小写转换,对于string类
find 泛型算法查找,找到返回指定值value的迭代器,否则返回最后一个位置迭代器
count 泛型算法统计数组中出现个数
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
using namespace std;
///
#define INF 0xffffff7
#define MAXN 200
///
vector< vector<int> > dictionary;
vector<string> words;
int main()
{
///
int i, j;
//读入字典
while (1)
{
string temp;
cin >> temp;
if (temp == "#")
break;
//将输入转化为小写格式
words.push_back(temp);
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
//转化为数组格式存储进入字典
vector<int> tempInput(26, 0);
vector<int>::iterator it = tempInput.begin();
string::iterator itor = temp.begin();
while (itor != temp.end())
{
(*(it + (*itor - 'a') ))++;
itor++;
}
vector< vector<int> >::iterator pTemp;
pTemp = find(dictionary.begin(), dictionary.end(), tempInput);
dictionary.push_back(tempInput);
}
//遍历字典查重
vector< vector<int> >::iterator pDic = dictionary.begin();
vector<string> outPut;
while (pDic != dictionary.end())
{
int mycount;
mycount = count(dictionary.begin(), dictionary.end(), *pDic);
if (mycount == 1)
{
outPut.push_back(words[pDic - dictionary.begin()]);
}
pDic++;
}
//排序以后按照字典顺序输出原始词语
sort(outPut.begin(), outPut.end());
vector<string>::iterator poutPut = outPut.begin();
while (poutPut != outPut.end())
{
cout << *poutPut << endl;
poutPut++;
}
///
return 0;
}