sdnu 1312.Morse code

1312.Morse code

Time Limit: 1000 MS    Memory Limit: 32768 KB
Total Submission(s): 39    Accepted Submission(s): 17

Description

Intelligencer Jason has just intercepted a cipher text, after seven days and nights he found the function how to crack the cipher, Jason’s ability of programming is pooooooor, so he comes to you to do him a favor.

      May you will not accept the request, but you must to do these job because Jason has just recommend you to the ***.

      Encryption Format:

 

 

Followed by the rule of encryption format:The plaintext is ” ACM_GREATER_NY_REGION”, after encrypted the cipher is “.- -.-. -- ..-- --. .-. . .- - . .-. ..-- -. -.-- ..-- .-. . --. .. --- -.”It is illegibility! You can decrypt the cipher “.--.-.--” to “ACM” or “ANY”, so Jason marked the cipher characters which need to be decrypted together by a series of numbers, like “.--.-.--242”, each number represents the length of the characters after encrypted into the cipher, so the cipher can be “ACM”.

You think it will be over? No! Jason hates the programmer, so raise the lever of the difficulty.

Before you decrypt the cipher in accordance with the number followed by the cipher you need to reverse these numbers.Like that:

Cipher:                “AKADTOF_IBOETATUK_IJN”

Middle_Cipher:  “.--.-.--..----..-...--..-...---.-.--..--.-..--...----.232313442431121334242”

Plaintext:            “ACM_GREATER_NY_REGION”

Input

Cipher(the length is no more than 100).

Output

Plaintext

Sample Input

AKADTOF_IBOETATUK_IJN

Sample Output

ACM_GREATER_NY_REGION

Source

Unknown
#include<bits/stdc++.h>
using namespace std;
string s[200];
void init()
{
    s['A']=".-";
    s['B']="-...";
    s['C']="-.-.";
    s['D']="-..";
    s['E']=".";
    s['F']="..-.";
    s['G']="--.";
    s['H']="....";
    s['I']="..";
    s['J']=".---";
    s['K']="-.-";
    s['L']=".-..";
    s['M']="--";
    s['N']="-.";
    s['O']="---";
    s['P']=".--.";
    s['Q']="--.-";
    s['R']=".-.";
    s['S']="...";
    s['T']="-";
    s['U']="..-";
    s['V']="...-";
    s['W']=".--";
    s['X']="-..-";
    s['Y']="-.--";
    s['Z']="--..";
    s['_']="..--";
    s[',']=".-.-";
    s['.']="---.";
    s['?']="----";
}
int main()
{
    string ss;
    init();
    int a[1000];
    while(cin>>ss)
    {
        string ans,tmp;
        memset(a,0,sizeof(a));
        for(int i=0;i<ss.length();++i)
        {
            tmp+=s[ss[i]];///...---...
            a[i]=s[ss[i]].length();///232323
        }
        reverse(a,a+ss.length());
        for(int i=0;i<ss.length();++i)
        {
            string tt(tmp,0,a[i]);
            tmp.erase(0,a[i]);
            for(int i=0;i<='z';i++)
            {
                if(s[i]==tt)
                {
                    ans+=(char)i;
                    break;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

 

 
posted @ 2019-07-22 09:10  观稳769  阅读(182)  评论(0编辑  收藏  举报