首页 > 其他分享 >uva 156 Ananagrams(字符串+STL应用)

uva 156 Ananagrams(字符串+STL应用)

时间:2023-07-26 17:31:40浏览次数:46  
标签:domain fino temp 156 STL will words uva include


                      uva 156 Ananagrams


Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPOT, STOP, POTS and POST. Some words however do not have this attribute, no matter how you rearrange their letters, you cannot form another word. Such words are called ananagrams, an example is QUIZ.

Obviously such definitions depend on the domain within which we are working; you might think that ATHENE is an ananagram, whereas any chemist would quickly produce ETHANE. One possible domain would be the entire English language, but this could lead to some problems. One could restrict the domain to, say, Music, in which case SCALE becomes a relative ananagram (LACES is not in the same domain) but NOTE is not since it can produce TONE.

Write a program that will read in the dictionary of a restricted domain and determine the relative ananagrams. Note that single letter words are, ipso facto, relative ananagrams since they cannot be ``rearranged'' at all. The dictionary will contain no more than 1000 words.

Input

Input will consist of a series of lines. No line will be more than 80 characters long, but may contain any number of words. Words consist of up to 20 upper and/or lower case letters, and will not be broken across lines. Spaces may appear freely around words, and at least one space separates multiple words on the same line. Note that words that contain the same letters but of differing case are considered to be anagrams of each other, thus tIeD and EdiT are anagrams. The file will be terminated by a line consisting of a single #.

Output

Output will consist of a series of lines. Each line will consist of a single word that is a relative ananagram in the input dictionary. Words must be output in lexicographic (case-sensitive) order. There will always be at least one relative ananagram.

Sample input


ladder came tape soon leader acme RIDE lone Dreis peat ScAlE orb eye Rides dealer NotE derail LaCeS drIed noel dire Disk mace Rob dries #


Sample output


Disk NotE derail drIed eye ladder soon




题目大意:找出满足条件的单词:不能通过重排在字符串中找到相同的单词(不分大小写)。

解题思路:这题是用来练STL的例题。


#include<iostream>
#include<string.h>
#include<cctype>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;

string strlow(string &s) {
	string temp = s;
	for (int i = 0; i < temp.length(); i++) {
		temp[i] = tolower(temp[i]);
	}
	sort(temp.begin(), temp.end());
	return temp;
}
map<string,int> map1;
vector<string> words;
int main() {
	string s;
	while (cin >> s) {
		if (s[0] == '#') break;
		words.push_back(s);
		string temp = strlow(s);
		if (!map1.count(temp)) map1[temp] == 0;
		map1[temp]++;
	}		
	vector<string> fino;
	for (int i = 0; i < words.size(); i++) {
		if (map1[strlow(words[i])] == 1) {
			fino.push_back(words[i]);
		}
	}
	sort(fino.begin(), fino.end());
	for (int i = 0; i < fino.size(); i++) {
		cout << fino[i] << "\n";
	}
	return 0;
}





标签:domain,fino,temp,156,STL,will,words,uva,include
From: https://blog.51cto.com/u_16206136/6858306

相关文章

  • JSTL 标签库详细介绍资料 .
     前言从JSP1.1规范开始,JSP就支持在JSP中使用自定义标签了,自定义标签的广泛使用造成了程序员重复定义,这样就促成了JSTL(JavaServerPagesStandardTagLibrary)的诞生。作者:丁令JSTL简介JSTL是一个不断完善的开放源代码的JSP标签库,是由apache的jakarta小组来维护的。JSTL只......
  • jstl tags
    前言=========================================================================JSTL标签库,是日常开发经常使用的,也是众多标签中性能最好的。把常用的内容,放在这里备份一份,随用随查。尽量做到不用查,就可以随手就可以写出来。这算是Java程序员的基本功吧,一定要扎实。 JSTL全名为J......
  • 117.STL中的multiset
    117.STL中的multiset1.multiset的介绍1.multiset是按照特定顺序存储元素的容器,其中元素是可以重复的2.在multiset在,元素的value也会识别它组成的键值对,multiset元素的值不能在容器中进行修改,但可以插入和删除3.在内部,multiset按照特定的严格弱排序准则进行排序4.multiset容......
  • 116.STL中的set
    116.STL中的set1.set的简介set的中文译为集合,知名见其意,因此set容器也就具有集合的属性啦!而集合这个概念大家应该上数学课应该都是学过的哈,集合它具有确定性、互异性、无序性。当然我们这里重点记住它的互异性就OK了,那么什么是互异性呢?就是说一个集合里边是不会出现两个甚至以上......
  • 115.STL中的multimap
    115.STL中的multimap1.multimap的基本性质multimap容器是和map容器相似的关联式容器,所谓“相似”,是指multimap容器具有和map容器相同的特性,即multimap容器也存储pair<constK,T>类型的键值对(其中K表示键的类型,T表示值的类型),其中各个键值对的键的值不能被修改;并且,该容器也会自行......
  • 114.STL中的map
    114.STL中的map1.map的简介map是C++STL中的一个关联式容器,它提供一对一的hash,它类似于Python中的字典,也有着键值对(Key-Value)这一说。我们可以通过键(Key)来找到值(Value),但需要注意的是,每个键(Key)只能在map中出现一次哦!map可以储存多种类型的数据,它主要用于一对一映射的情况,map内部......
  • 113.STL中的pair
    113.STL中的pair1.pair的简介pair是C++STL(标准模板库)中的一个现有容器,它将2个数据整合成一组数据,当我们类似需求的时候就可以使用到pair啦!pair其实有点像Python中字典中的键值对(Key-Value),一个Key对应着一个Value。pair的本质其实就是个结构体,它含有两个成员变量first和second。......
  • C++ stl锁的使用
    我们在日常开发中经常要用到锁,这里记录一下实际开发过程中stl提供的锁的使用。1、读写锁读写锁算是用到的比较多的一种类型,主要实现对于同一个共享数据区,一个时间点只能有一个线程进行写(增删改),但可以有多个线程同时读(查)。换句话说,当有一个线程写的时候,其他线程(不管是读线程还是......
  • 112.STL中的array
    112.STL中的array1.array介绍在C++标准库中,array是固定大小的序列容器,array中包含特定个数并且严格按照线性序列排序的元素。因此array允许对元素进行随机访问,指向某一元素的指针可以通过偏移访问其他元素。在array内部,它只保存自己包含的元素,其他任何信息都不保存,包括自身的大......
  • UVA??? 考试 Exam
    本来这篇题解是想在中考前写的,但是直到考前都没调出来,原因是pow()的精度感人。由于\(x\equiv0\pmod{a\cdotb}\),令\(c=\dfrac{x}{ab}\),答案即\(abc\len\)的无序三元组\((a,b,c)\)数量。考虑把无序转成有序,即\(a\leb\lec\),但显然会算少,分\(4\)种情况讨论:\(a=b=c=......