【链接】 我是链接,点我呀:)

【题意】

给你每个字母对应的摩斯密码。
然后每个单词的莫斯密码由其组成字母的莫斯密码连接而成。
现在给你若干个莫斯密码。
请问你每个莫斯密码对应哪个单词。
如果有多个单词和他对应。那么输出字典序最小的那个。
如果没有单词和他对应。
那么,你可以删除或者添加若干字母(只能一直删或一直增加)
问你在这种情况下能匹配到的单词(要求添加或者删的单词的数量最小)
如果有多种可能。输出字典序最小的。

如果一直删除。一直增加也找不到。

那么输出所有单词里面字典序最小的哪个。

【题解】

模拟就好。
先对字典排个序再模拟。

【代码】

  1. #include <bits/stdc++.h>
  2. #define rep1(i,a,b) for (int i = a;i <= b;i++)
  3. #define rep2(i,a,b) for (int i = a;i >= b;i--)
  4. using namespace std;
  5. const int N = 1e3;
  6. int n;
  7. string s;
  8. string dic[300];
  9. vector<pair<string,string> > v;
  10. string _find(string s){
  11. int step = 0;string ans = "";
  12. rep1(i,0,(int)v.size()-1){
  13. if (v[i].second==s) {
  14. if (step==0) ans = v[i].first;
  15. step++;
  16. }
  17. }
  18. if (step>0){
  19. if (step>1) ans+="!";
  20. return ans;
  21. }
  22. step = -1;
  23. int len1 = s.size();
  24. rep1(i,0,(int)v.size()-1){
  25. int len2 = v[i].second.size();
  26. if (len2<len1){
  27. string temp = s.substr(0,len2);
  28. if (temp==v[i].second){
  29. if (step==-1){
  30. step = len1-len2;
  31. ans = v[i].first;
  32. }else if (len1-len2<step){
  33. step = len1-len2;
  34. ans = v[i].first;
  35. }
  36. }
  37. }else{
  38. //len2>=len1
  39. string temp = v[i].second.substr(0,len1);
  40. if (temp==s){
  41. if (step==-1){
  42. step = len2-len1;
  43. ans = v[i].first;
  44. }else if (len2-len1<step){
  45. step = len2-len1;
  46. ans = v[i].first;
  47. }
  48. }
  49. }
  50. }
  51. if (step==-1) ans = v[0].first;
  52. ans+="?";
  53. return ans;
  54. }
  55. int main(){
  56. //freopen("/home/ccy/rush.txt","r",stdin);
  57. // freopen("/home/ccy/rush_out.txt","w",stdout);
  58. ios::sync_with_stdio(0),cin.tie(0);
  59. while (cin >> s){
  60. if (s[0]=='*') break;
  61. string cor;
  62. cin >> cor;
  63. dic[s[0]] = cor;
  64. }
  65. while (cin >> s){
  66. if (s[0]=='*') break;
  67. string temp = "";
  68. rep1(i,0,(int)s.size()-1){
  69. temp += dic[s[i]];
  70. }
  71. v.push_back({s,temp});
  72. }
  73. sort(v.begin(),v.end());
  74. while (cin >> s){
  75. if (s[0]=='*') break;
  76. cout<<_find(s)<<endl;
  77. }
  78. return 0;
  79. }

【习题 4-6 UVA - 508】Morse Mismatches的更多相关文章

  1. uva 508 - Morse Mismatches(摩斯码)

    来自https://blog.csdn.net/su_cicada/article/details/80084529 习题4-6 莫尔斯电码(Morse Mismatches, ACM/ICPC Wo ...

  2. uva 508 Morse Mismatches

    Samuel F. B. Morse is best known for the coding scheme that carries his name. Morse code is still us ...

  3. UVA 508 Morse Mismatches JAVA

    题意:输入字母和数字的编码,输入词典,输入一段编码,求出对应的单词. 思路:来自https://blog.csdn.net/qq_41163933/article/details/82224703 i ...

  4. UVa 508 Morse Mismatches (模糊暴力)

    题意:莫尔斯电码,输入若干个字母的Morse编号,一个字典和若干编码.对于每个编号,判断它可能的是哪个单词, 如果有多个单词精确匹配,输出第一个单词并加一个“!”:如果无法精确匹配,那么在编码尾部增加 ...

  5. [刷题]算法竞赛入门经典(第2版) 4-6/UVa508 - Morse Mismatches

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,10 ms) //UVa508 - Morse Mismatches #include< ...

  6. ACM训练计划建议(写给本校acmer,欢迎围观和指正)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  7. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  8. 动态规划 Dynamic Programming 学习笔记

    文章以 CC-BY-SA 方式共享,此说明高于本站内其他说明. 本文尚未完工,但内容足够丰富,故提前发布. 内容包含大量 \(\LaTeX\) 公式,渲染可能需要一些时间,请耐心等待渲染(约 5s). ...

  9. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

随机推荐

  1. hive-0.11.0安装方法具体解释

    先决条件:     1)java环境,须要安装java1.6以上版本号     2)hadoop环境,Hadoop-1.2.1的安装方法參考hadoop-1.2.1安装方法具体解释 本文採用的hado ...

  2. ASP.NET MVC中的嵌套布局页

    在WEB窗体模式中,用惯了母版页,并且常有母版页嵌套的情况. 而在MVC模式下,对应母版页的,称作为布局页.默认的布局页为 ~/Views/Shared/_Layout.cshtml.默认每个页面都会 ...

  3. 阿里云 Docker-registry 搭建

    阿里云 仓库地址: https://cr.console.aliyun.com/cn-hangzhou/instances/images

  4. Linux下使用popen()执行shell命令【转】

    本文转载自:https://my.oschina.net/u/727148/blog/262987 函数原型: #include “stdio.h” FILE popen( const char co ...

  5. SpringMVC使用POST方法传递数据,却出现Request method 'GET' not supported?

    转自:https://segmentfault.com/q/1010000011245770 问题:没有使用get获取当前页面解决方案:   @RequestMapping(value = " ...

  6. 快速掌握C#7

    1. out 变量(out variables) 以前我们使用out变量必须在使用前进行声明,C# 7.0 给我们提供了一种更简洁的语法 “使用时进行内联声明” .如下所示: var input = ...

  7. [转]利用 NPOI 變更字體尺寸及樣式

    本文转自:http://blog.cscworm.net/?p=1650 利用 NPOI 變更字體尺寸及樣式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  8. BZOJ 3930 容斥原理

    思路: 移至iwtwiioi    http://www.cnblogs.com/iwtwiioi/p/4986316.html //By SiriusRen #include <cstdio& ...

  9. BZOJ 4753 二分+树形DP

    思路: 先二分答案 f[x][j]表示在x的子树里选j个点 f[x][j+k]=max(f[x][j+k],f[x][j]+f[v[i]][k]); 初始化 x!=0 -> f[x][1]=p[ ...

  10. 自学Python九 爬虫实战二(美图福利)

    作为一个新世纪有思想有文化有道德时刻准备着的屌丝男青年,在现在这样一个社会中,心疼我大慢播抵制大百度的前提下,没事儿上上网逛逛YY看看斗鱼翻翻美女图片那是必不可少的,可是美图虽多翻页费劲!今天我们就搞 ...