UVa-156 Ananagrams(map映射)

参考:https://blog.csdn.net/hoaresky1998/article/details/51351588

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <set>
 5 #include <map>
 6 #include <algorithm>
 7 using namespace std;
 8 map<string,int> ma;
 9 set<string> sea;
10 string change(string x)
11 {
12     for (unsigned int i=0;i<x.length();i++)
13     {
14        x[i]=towlower(x[i]);
15     }
16     sort(x.begin(),x.end());//排序string类型的方法
17     return x;
18 }
19 int main()
20 {
21 //    freopen("in.txt","r",stdin);
22     string s;
23     while (cin>>s)
24     {
25         if (s=="#")
26         {
27             break;
28         }
29         sea.insert(s);//运用set自身的有序性
30         string temp=change(s);//转化为小写形式,且字母按字典序排序
31         if (!ma.count(temp))
32         {
33             ma[temp]=1;
34         }
35         else
36         {
37             ma[temp]++;
38         }
39     }
40     set<string>::iterator it;
41     for (it=sea.begin();it!=sea.end();it++)
42     {
43         if (ma[change(*it)]==1)
44         {
45             cout<<*it<<endl;
46         }
47     }
48
49     return 0;
50 }

原文地址:https://www.cnblogs.com/hemeiwolong/p/9600837.html

时间: 2024-10-06 01:20:03

UVa-156 Ananagrams(map映射)的相关文章

UVA 156 Ananagrams 关于二维数组表示的字符串排序的问题

题目链接:UVA 156 Ananagrams  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

uva 156 - Ananagrams (反片语)

csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文 本中的另外一个单词. 在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中 的大小写,按字典序进行排列(所有大写字母在所有小写字母的前面). Sample Input ladder came tape soon leader ac

UVa 156 Ananagrams(STL,map)

 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 let

UVa 156 (stl map的使用)

  一.map map就是从键(key)到值(value)的映射,重载了[]所以可以认为是高级版的数组,常用的一些操作如下: 头文件:#include<map> 定义:map <类型一(key),类型二(value)> name  key称为map的frist,value称为map的second. 初始化:name.clear(); 二.题目 Ananagrams Most crossword puzzle fans are used to anagrams--groups of

UVa 156 - Ananagrams

 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 let

uva 156 (map)

暑假培训习题 1.用vector<string>储存string类型的输入单词: 2.将vector中的元素逐一标准化后映射进map中,并给map值加一: 3.新建一个空的vector 4.标准化之前的vector中的元素,并查看map中的值,如果是一,则把这个元素压入新的vector中,给新的vector排序并输出: #include<stdio.h>#include<map>#include<string>#include<algorithm>

STL语法——映射:map 反片语(Ananagrams,UVa 156)

Description 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 lett

Ananagrams 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 l

map——映射(message.cpp)

信息交换 (message.cpp) [题目描述] Byteland战火又起,农夫John派他的奶牛潜入敌国获取情报信息. Cow历尽千辛万苦终于将敌国的编码规则总结如下: 1 编码是由大写字母组成的字符串. 2 设定了密字.加密的过程就是把原信息的字母替换成对应密字. 3 一个字母有且仅有一个对应密字,不同字母对应不同密字. 如今,Cow终于获取了敌国发送的一条加密信息和对应的原信息.Cow如下破解密码:扫描原信息,对于原信息中的字母x,找到它在加密信息中的对应大写字母y,且认为y是x的密字.