UVA 156 反片语

先输入字典,查找有没有通过排列组合能够不重复的词,忽略大小写

采用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;

}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值