[Exercise 4-6 UVA-508] Morse mismatches

Source: Internet
Author: User

[LINK] I am a link. Click me :)
Question]


Give you the moss password for each letter.
Then the mos password for each word is connected by the mos password, which is a letter.
Now I will give you several MOS passwords.
Which word does your Moz password correspond.
If multiple words correspond to one another. The smallest lexicographic output.
If no word matches him.
Then, you can delete or add several letters (you can only delete them all the time or add them all the time)
Ask the words that can be matched in this case (requires the minimum number of words to be added or deleted)
If there are multiple possibilities. The smallest Lexicographic Order is output.

If you delete it all the time. It cannot be found even if it keeps increasing.
Which of the following statements outputs the smallest Lexicographic Order of all words.

[Question]


Simulate it.
Sort the dictionary order before simulation.

[Code]

#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;}

[Exercise 4-6 UVA-508] Morse mismatches

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.