【习题 4-6 UVA - 508】Morse Mismatches
【链接】 我是链接,点我呀:)
【题意】
给你每个字母对应的摩斯密码。
然后每个单词的莫斯密码由其组成字母的莫斯密码连接而成。
现在给你若干个莫斯密码。
请问你每个莫斯密码对应哪个单词。
如果有多个单词和他对应。那么输出字典序最小的那个。
如果没有单词和他对应。
那么,你可以删除或者添加若干字母(只能一直删或一直增加)
问你在这种情况下能匹配到的单词(要求添加或者删的单词的数量最小)
如果有多种可能。输出字典序最小的。
如果一直删除。一直增加也找不到。
那么输出所有单词里面字典序最小的哪个。
【题解】
模拟就好。
先对字典排个序再模拟。
【代码】
#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;
const int N = 1e3;
int n;
string s;
string dic[300];
vector<pair<string,string> > v;
string _find(string s){
int step = 0;string ans = "";
rep1(i,0,(int)v.size()-1){
if (v[i].second==s) {
if (step==0) ans = v[i].first;
step++;
}
}
if (step>0){
if (step>1) ans+="!";
return ans;
}
step = -1;
int len1 = s.size();
rep1(i,0,(int)v.size()-1){
int len2 = v[i].second.size();
if (len2<len1){
string temp = s.substr(0,len2);
if (temp==v[i].second){
if (step==-1){
step = len1-len2;
ans = v[i].first;
}else if (len1-len2<step){
step = len1-len2;
ans = v[i].first;
}
}
}else{
//len2>=len1
string temp = v[i].second.substr(0,len1);
if (temp==s){
if (step==-1){
step = len2-len1;
ans = v[i].first;
}else if (len2-len1<step){
step = len2-len1;
ans = v[i].first;
}
}
}
}
if (step==-1) ans = v[0].first;
ans+="?";
return ans;
}
int main(){
//freopen("/home/ccy/rush.txt","r",stdin);
// freopen("/home/ccy/rush_out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0);
while (cin >> s){
if (s[0]=='*') break;
string cor;
cin >> cor;
dic[s[0]] = cor;
}
while (cin >> s){
if (s[0]=='*') break;
string temp = "";
rep1(i,0,(int)s.size()-1){
temp += dic[s[i]];
}
v.push_back({s,temp});
}
sort(v.begin(),v.end());
while (cin >> s){
if (s[0]=='*') break;
cout<<_find(s)<<endl;
}
return 0;
}
【习题 4-6 UVA - 508】Morse Mismatches的更多相关文章
- uva 508 - Morse Mismatches(摩斯码)
来自https://blog.csdn.net/su_cicada/article/details/80084529 习题4-6 莫尔斯电码(Morse Mismatches, ACM/ICPC Wo ...
- uva 508 Morse Mismatches
Samuel F. B. Morse is best known for the coding scheme that carries his name. Morse code is still us ...
- UVA 508 Morse Mismatches JAVA
题意:输入字母和数字的编码,输入词典,输入一段编码,求出对应的单词. 思路:来自https://blog.csdn.net/qq_41163933/article/details/82224703 i ...
- UVa 508 Morse Mismatches (模糊暴力)
题意:莫尔斯电码,输入若干个字母的Morse编号,一个字典和若干编码.对于每个编号,判断它可能的是哪个单词, 如果有多个单词精确匹配,输出第一个单词并加一个“!”:如果无法精确匹配,那么在编码尾部增加 ...
- [刷题]算法竞赛入门经典(第2版) 4-6/UVa508 - Morse Mismatches
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,10 ms) //UVa508 - Morse Mismatches #include< ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- ACM训练计划建议(转)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- 动态规划 Dynamic Programming 学习笔记
文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
随机推荐
- iOS - 社会化分享-微信分享,朋友圈分享
我仅仅做了文字和图片分享功能 1. TARGETS - Info - URL Types identifier -> weixin URL Schemes -> 应用id 2.在AppD ...
- Django网站管理--ModelAdmin
class AuthorAdmin(admin.ModelAdmin): list_display=('name', 'age', 'sex') #指定要显示的字段 search_fields=('n ...
- HDU5195 线段树+拓扑
DZY Loves Topological Sorting Problem Description A topological sort or topological ordering of a di ...
- 的Linq未提交之前插入/修改时重新查询不准确问题
来园子已经两年了,每次都是看,这次咱也写一次. 说一下今天遇到的Linq问题: 每一次插入流水表时,都需要查找表中最大的流水号+1,并且将该流水号返回,但是在同一个SubmitChange之内插入多条 ...
- class--类②
定义 C++ 对象 类提供了对象的蓝图,所以基本上,对象是根据类来创建的.声明类的对象,就像声明基本类型的变量一样.下面的语句声明了类 Box 的两个对象: Box Box1; // 声明 Box1, ...
- spring boot测试
今天在springside里试了spring boot,果然很方便,内置容器,不需要配置web.xml,简单几个文件就可以实现增删改查操作,一些配置如tomcat端口之类的直接写在applicatio ...
- [HDU4689]Derangement
https://zybuluo.com/ysner/note/1232641 题面 给出\(b_1,b_2,...,b_n\in\{−1,1\}\),求满足\((p_i−i)*b_i<0\)的\ ...
- EOJ 3023 字符组合
3.30更新 #include <iostream> #include <stdio.h> #include <algorithm> #include <se ...
- mysql重设root的密码 mac
创建: 2017/09/14 第一步: 关闭已开启的mysql服务器 mysql.server stop 第二步: 关闭密码识别模式 /usr/local/bin/mysqld_safe ...
- git clone 出现错误
看了好多资料终于搞定了git 中clone命令报错这个问题,废话不多说直接上步骤希望对大家有帮助. 1 删除.ssh文件夹(直接搜索该文件夹)下的known_hosts(手动删除即可,不需要git ...