反片语(UVa156)
1.将输入的单词标准化:单词字母转为小写,再将单词排序
2.将排序后的单词存入map中,当有相同的key时,也即意味着两个单词之间可以通过字母重排互相转化,key对应的value记录重复的数值,值为1即为我们要找的单词
C++11代码如下:
#include<iostream>
#include<vector>
#include<map>
#include<cctype>
#include<algorithm>
#include<string> using namespace std;
map<string, int>cnt;
vector<string>word;
string repr(const string&s) { //标准化
string ans=s;
for (int i = ; i < s.length(); i++) {
ans[i] = tolower(s[i]);
}
sort(ans.begin(), ans.end());
return ans;
} int main() {
string s;
while (cin >> s) {
if (s[] == '#') break;
word.push_back(s);
string r = repr(s);
if (!cnt.count(r)) cnt[r] = ; //count函数统计map中key出现的次数,为0或1
cnt[r]++;
}
vector<string>ans;
for(vector<string>::iterator it=word.begin();it!=word.end();it++)
if (cnt[repr(*it)] == ) ans.push_back(*it);
sort(ans.begin(), ans.end());
for (vector<string>::iterator it = ans.begin(); it != ans.end(); it++)
cout << *it << endl;
return ;
}
反片语(UVa156)的更多相关文章
- uva 156 - Ananagrams (反片语)
csdn:https://blog.csdn.net/su_cicada/article/details/86710107 例题5-4 反片语(Ananagrams,Uva 156) 输入一些单词,找 ...
- UVa-156 Ananagrams 反片语【map】【vector】
题目链接:https://vjudge.net/contest/211547#problem/D 题目大意: 输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一些 ...
- 算法习题---5.4反片语(Uva156)
一:题目 输入一些单词,找出所有满足以下条件的单词:该单词不能通过字母重排得到输入文本中的另外一个单词.在判断是否满足条件时,字母不区分大小写,但在输出时应该保留输入中的大小写,按字典序进行排列 将输 ...
- 5_4 反片语(UVa156)<map的使用>
输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母不区分大小写,但在输出的时候保留输入时的大小写,按字典序进行排列. 样例输入: ...
- 反片语(map)
输入一些单词,找出所有满足如下条件的单词: 该单词不能通过字母重排,得到输入文本中的另外一个单词. 在判断是否满足条件时,不区分大小写,但输出保留输入中的大小写,按字典序进行排列(所有大写字母在小写字 ...
- STL语法——映射:map 反片语(Ananagrams,UVa 156)
Description Most crossword puzzle fans are used to anagrams--groups of words with the same letters i ...
- 反片语 UVA 156
//该单词不能通过字母重排,得到输入文本中的另外一个单词.在判断是否满足条件时,字母部分大小写 #include<iostream> #include<vector> #inc ...
- 反片语 (Ananagrams,UVa 156)
题目描述: #include <iostream> #include <string> #include <cctype> #include <vector& ...
- 反片语(Ananagrams,Uva 156)
输入一些单词,找出所有满足如下条件的单词:该单词不能通过字母重排,得到输入文 本中的另外一个单词.在判断是否满足条件时,字母不分大小写,但在输出时应保留输入中 的大小写,按字典序进行排列(所有大写字母 ...
随机推荐
- linux小命令集合
du -sh * 查看当前目录下的当前子目录的内存大小 df -h 查看内存占用情况 tar -xvf src.tgz ; rsync -avzL src/ desc/ lin ...
- 2017 Multi-University Training Contest - 2
HDU 6045 #pragma comment(linker, "/STACK:102400000,102400000") #include <cstdio> #in ...
- poj 3254 状态压缩
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15285 Accepted: 8033 Desc ...
- 【题解】【LibreOJ Round #6】花团 LOJ 534 时间线段树分治 背包
Prelude 题目链接:萌萌哒传送门(/≧▽≦)/ Solution 如果完全离线的话,可以直接用时间线段树分治来做,复杂度\(O(qv \log q)\). 现在在线了怎么办呢? 这其实是个假在线 ...
- Jenkins CI Pipeline scripting
Jenkins pipeline is a suite of Jenkins plugins. Pipelines can be seen as a sequence of stages to per ...
- 使用rabbitmq消息队列
一.前言 在python中本身就是存在队列queue.一个是线程队列queue,另一个是进程multiprocessing中的队列Queue. 线程queue:只用于线程之间的数据交互 进程Queue ...
- 「Django」rest_framework学习系列-权限认证
权限认证:1.项目下utils文件写permissions.py文件 from rest_framework.permissions import BasePermission class SVIPP ...
- synchronized 加锁Integer对象(数据重复)详解
场景描述:多线程输出1到100,对静态Integer对象加锁,synchronized代码块中操作Integer对象,发生线程安全问题(数据重复) 代码: public class MyRunnabl ...
- 【CodeForces】866D. Buy Low Sell High
[题意]已知n天股价,每天可以买入一股或卖出一股或不作为,最后必须持0股,求最大收益. [算法]堆 贪心? [题解] 不作为思想:[不作为=买入再卖出] 根据不作为思想,可以推出中转站思想. 中转站思 ...
- http://www.cnblogs.com/kkdn/
/*** PHP保留两位小数的几种方法* @link http://www.phpddt.com*/$num = 10.4567; //第一种:利用round()对浮点数进行四舍五入echo roun ...