7296 Morse

map操作

A code developed by Samuel Morse was first used as a method of electronic communication between

two operators sending long and short electrical impulses. These impulses would activate an armature

equipped with an electromagnet. The duration of the impules and the silence between them evolved

into what is now known as Morse Code.

Letters are represented with a series of dots and/or dashes. SOS , the universal distress call, is represented by ‘... --- ...’ (S =...and O =---). Typically, letters are separated by long pauses between them, otherwise they cannot be properly distinguished. Without the proper pauses, the code gets obfuscated.

The word ACM is represented in Morse Code by ‘.- -.-. --’, but ANY is represented by ‘.- -.-.--’ and without the spacing between code letters, the words ACM and ANY are indistinguishable(.--.-.--).

Input

Input consists of the morse code conversion followed by a dictionary of valid words, then a number of test cases with words in morse code.

The first 26 lines of input each contain a unique upper case letter, a single space, and the morse code equivalent. The letters are in alphabetical order. The morse code equivalents will be exactly the same as the ones below in Sample Input.The next line contains the number of valid words,N(1 <=N <=100). The following N lines each contain a word containing 1 to 100 uppercase letters.

The dictionary is followed by one or more test cases. Each begins with a line containing the number of code words W(1 <=W<= 100) or 0 (zero) indicating end of input. The following W lines each contain a code word, in morse code, with no spacing between individual code letters. Each code word will contain 1 to 400 ‘.’ and/or ‘-’ symbols. If a codeword matches a word in the dictionary, it will only match a single word in the dictionary.

Output

For each test case, if all of the codewords are found in the dictionary, print a line containing the

corresponding alphabetical word of each code word in a sentence on one line with each word separated

by a single space. If any codeword in the input does not appear in the dictionary, report only the first

such codeword followed by ‘not in dictionary.’ and do not print any corresponding alphabetical words.

Sample Input

A .-

B -...

C -.-.

D -..

E .

F ..-.

G --.

H ....

I ..

ACM-ICPC Live Archive:

7296 – Morse

2/2

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

代码:

#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
#include<queue>
#include<vector>
#include<stack>
#include<map>
typedef long long int LL;
#define MAX 100010
int main()
{
    int i,j,n,m;
    char a;
    string b,c,d,e,s[1000],f[1000];
    map<char,string>mp1;
    map<string,string>mp2;
    for(i=0;i<26;i++)
    {
        cin>>a>>b;
        mp1[a]=b;
    }
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
        c.clear();
        for(j=0;j<s[i].length();j++)
        {
            d=mp1[s[i][j]];
            c+=d;
        }
        mp2[c]=s[i];
    }
    while(scanf("%d",&m)!=EOF&&m!=0)
    {
        int p=-1,flag=0,bl=0,k=0;
        for(i=0;i<m;i++)
        {
            cin>>e;
            if(flag==1)
                continue;
            if(mp2.count(e)==0)
            {
                cout<<e<<" not in dictionary."<<endl;
                flag=1;
            }
            else
                f[k++]=mp2[e];
        }
        if(flag==0)
        {
            for(i=0;i<k;i++)
            {
                if(i==0)
                    cout<<f[i];
                else
                    cout<<" "<<f[i];
            }
            cout<<endl;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值