HDOJ HDU 1113 Word Amalgamation
来源:互联网 发布:网络大电影投资公司 编辑:程序博客网 时间:2024/06/05 11:08
HDOJ 1113 Word Amalgamation
题目
点此查看 HDOJ 1113 Word Amalgamation
分类
模拟
字符处理
题意
给出 几个词 做字典
接下来给出的词 找 字典里 的 词 是否存在 乱序 后的该词 存在 输出字典中的词根
字典
tarp
refund
trap
part
词
nfudre 输出 refund
aptr 输出
part
tarp
trap
sett 输出 NOT A VALID WORD
注意第二个词 的输出 有多个词根时要按字典序全部输出
题解
按题意模拟即可
技巧
怎么样对比
词典和词呢
我们可以将词典和词全部 “标准化”
由于词是乱序过的
那么 我们排序在比较即可
标准化的词根要对应词库中的词 由于是 一对多的关系 可以用 mutimap实现
代码
#include <iostream>#include <queue>#include <algorithm>#include <map>using namespace std;multimap<string,string> m;string Amalgamation(string s);bool cmp(const string & a,const string & b){ return a < b; };priority_queue<string,vector<string>,greater<string> > q;int main(){ string line; while(getline(cin,line) && line != "XXXXXX") { string key = Amalgamation(line); m.insert(pair<string,string>(key,line)); } while(getline(cin,line) && line != "XXXXXX") { string key = Amalgamation(line); int num = m.count(key); if(num == 0) cout << "NOT A VALID WORD" << endl; else { multimap<string,string>::iterator it; it = m.find(key); for(int i = 0;i < num;i++) {// cout << (*it).second << endl;] q.push((*it).second); it++; } while(!q.empty()) { cout << q.top() << endl; q.pop(); } } cout << "******" << endl; } return 0;}string Amalgamation(string s){// string am; sort(s.begin(),s.end());// am += s[0];/* for(int i = 1;i < s.length();i++) { if(s[i] == s[i-1]) continue; am += s[i]; }*/ return s;}
阅读全文
0 0
- HDOJ HDU 1113 Word Amalgamation
- HDOJ 1113 Word Amalgamation
- hdoj 1113 Word Amalgamation
- hdoj 1113 Word Amalgamation
- HDU 1113 Word Amalgamation
- hdu 1113 Word Amalgamation
- hdu(1113)Word Amalgamation
- HDU 1113 Word Amalgamation
- hdu 1113 Word Amalgamation
- HDU 1113 Word Amalgamation
- HDU 1113-Word Amalgamation
- hdu 1113 Word Amalgamation
- hdu 1113 Word Amalgamation
- hdu 1113 Word Amalgamation
- hdu-1113 Word Amalgamation
- HDU 1113 Word Amalgamation
- HDU 1113 Word Amalgamation
- HDOJ/HDU 1113 Word Amalgamation(字典顺序~Map)
- Java日记(6)— 面向对象特性
- [Kotlin]Kotlin二进制读写
- CSDN-markdown编辑器
- struts2+ajaxfileupload.js实现单文件传输
- 从MySQL数据库读取图片和向数据库插入图片
- HDOJ HDU 1113 Word Amalgamation
- Unity3D中在Inspector面板中显示复合属性信息(类属性/Struct属性)
- 使用superlance插件增强supervisor的监控能力
- No package python-pip available. 解决方法
- HDU 4081 Qin Shi Huang's National Road System (次小生成树)
- java实现聊天室功能(包含全部代码,有界面)
- 常用正则表达式大全。
- sklearn参数优化方法
- win10 jdk 的配置