码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 508 - Morse Mismatches (UVA)


    题目链接如下:

    Online Judge

    这道题我觉得题意有点问题,它写“If multiple context words match morse perfectly, then select the matching word with the fewest characters.”,但按这个题意写的代码无法AC,只能选择最先perfectly match的那个词。

    AC代码如下:

    1. #include
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. const int INF = 10000;
    9. int pivot, minGap, pivotGap;
    10. std::vector word, strVec;
    11. char ch[11];
    12. std::string s;
    13. std::map<char, std::string> mp;
    14. bool flag;
    15. int calGap(std::string a, std::string b){
    16. for(int i = 0; i < std::min(a.size(), b.size()); ++i){
    17. if(a[i] != b[i]){
    18. return INF;
    19. }
    20. }
    21. return std::max(a.size(), b.size()) - std::min(a.size(), b.size());
    22. }
    23. int main(){
    24. while(scanf("%s", ch) == 1 && ch[0] != '*'){
    25. std::cin >> s;
    26. mp[ch[0]] = s;
    27. }
    28. while(scanf("%s", ch) == 1 && ch[0] != '*'){
    29. std::string str;
    30. for(int i = 0; i < strlen(ch); ++i){
    31. str += mp[ch[i]];
    32. }
    33. word.push_back(ch);
    34. strVec.push_back(str);
    35. }
    36. while(std::cin >> s && s != "*"){
    37. bool exclamation = false;
    38. flag = false;
    39. minGap = INF;
    40. for(int i = 0; i < strVec.size(); ++i){
    41. if(strVec[i] == s){
    42. if(!flag){
    43. pivot = i;
    44. flag = true;
    45. } else{
    46. exclamation = true;
    47. }
    48. } else{
    49. int tmp = calGap(s, strVec[i]);
    50. if(tmp < minGap){
    51. minGap = tmp;
    52. pivotGap = i;
    53. }
    54. }
    55. }
    56. if(flag){
    57. printf("%s%s\n", word[pivot].c_str(), exclamation ? "!" : "");
    58. } else{
    59. printf("%s?\n", word[pivotGap].c_str());
    60. }
    61. }
    62. return 0;
    63. }

  • 相关阅读:
    一文彻底搞懂ZAB算法,看这篇就够了!!!
    C# 第二章『基础语法』◆第2节:switch case语句
    1024动态
    pytorch代码迁移到mindspore时,API的替换问题
    高阶数据结构学习 —— 图(4)
    探店通系统源码,短视频矩阵源码独立部署,look here
    swift UITextField 设置leftView不生效
    进程与线程
    Python-Opencv应用实例之头发自动分割、计数、特征统计智能分析系统
    线路质检用的到底多不多?
  • 原文地址:https://blog.csdn.net/linh2006/article/details/133673577
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号