csuoj-1716-Morse

Description

csuoj-1716-Morse_第1张图片

Input

csuoj-1716-Morse_第2张图片

Output

Sample Input

A .-
B -...
C -.-.
D -..
E .
F ..-.
G --.
H ....
I ..
J .---
K -.-
L .-..
M --
N -.
O ---
P .--.
Q --.-
R .-.
S ...
T -
U ..-
V ...-
W .--
X -..-
Y -.--
Z --..
7
PROGRAMMING
REGIONAL
PARIS
CONTEST
CENTRAL
SOUTH
ACM
6
.--.-.--
...---..--....
-.-..-.-.-..-.-..
.-..--...----..-.-..
.--..-.-----..-..-----..-.--.
-.-.----.-....-
4
.--.-.--
.-...---..-
.-...---..-.
.--.-.--
1
.--..-.-......
0

Sample Output

ACM SOUTH CENTRAL REGIONAL PROGRAMMING CONTEST
.-...---..- not in dictionary.
PARIS


给你字母所代表的符号啊,然后给你几个字典里的单词啊,然后让你找啊找的。

用stl里的map和vector可以水过去,数据很小。看代码就能懂了

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <map>
using namespace std;
const int maxn = 105;
map<char, string> alpha;
map<int, string> res;
vector<int> v;
string dict[maxn], temp[maxn];
string ans[maxn];
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char ch;
    string str;
    while (cin >> ch >> str){
        alpha.clear();
        res.clear();
        alpha[ch] = str;
        for (int i=1; i<26; ++i){
            cin >> ch >> str;
            alpha[ch] = str;
        }
        int num;
        cin >> num;
        for (int i=0; i<num; ++i)
            cin >> dict[i];
        for (int i=0; i<maxn; ++i)
            ans[i].clear();
        for (int i=0; i<num; ++i){
            for (int j=0; j<dict[i].size(); ++j)
                ans[i] += alpha[dict[i][j]];
            res[i] = dict[i];
        }
        int n;
        while (cin >> n && n != 0){
            for (int i=0; i<n; ++i)
                cin >> temp[i];
            bool ok = true;
            v.clear();
            int l;
            for (int i=0; i<n; ++i){
                int j;
                for (j=0; j<num; ++j)
                    if (ans[j] == temp[i]){
                        v.push_back(j);
                        break;
                    }
                if (j >= num){
                    l = i;
                    ok = false;
                    break;
                }
            }
            if (ok){
                for (int i=0; i<v.size(); ++i){
                    if (i > 0)
                        cout << " ";
                    cout << res[v[i]];
                }
                cout << endl;
            }
            else{
                cout << temp[l] << " " << "not in dictionary." << endl;
            }
        }
    }
    return 0;
}


你可能感兴趣的:(模拟,STL)