• 【习题 4-6 UVA


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

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

    如果一直删除。一直增加也找不到。
    那么输出所有单词里面字典序最小的哪个。

    【题解】

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

    【代码】

    #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;
    }
    
    
  • 相关阅读:
    PE文件结构详解(六)重定位
    PE文件结构详解(五)延迟导入表
    PE文件结构详解(四)PE导入表
    PE文件结构详解(三)PE导出表
    PE文件结构详解(二)可执行文件头
    PE文件结构详解(一)基本概念
    querySelector与getElementBy等的区别
    区别getElementByID,getElementsByName,getElementsByTagName
    css 只改变父元素的透明度,不改变子元素透明度rgba+opacity
    windows下配置apache+https
  • 原文地址:https://www.cnblogs.com/AWCXV/p/9879080.html
Copyright © 2020-2023  润新知