Etnetera Brevity Challenge

Your task is to implement a decoder of the famous Morse alphabet. As most of you know,
the Morse code represents characters as variable-length sequences of short and long signals
(“beeps”), often written as dots and dashes. For those who do not remember their scouting
years, the following table shows the Morse code sequences for all letters:

A .- E . I .. M – Q –.- U ..- Y -.–
B -… F ..-. J .— N -. R .-. V …- Z –..
C -.-. G –. K -.- O — S … W .–
D -.. H …. L .-.. P .–. T - X -..-

If more letters are to be transferred, they are separated by a short pause, typically written as
a slash. A space between words is represented by an even longer pause, written as two slashes.
Input Specification
The input contains several test cases. Each test case is specified on one line with at most 1000
characters, which describes a valid Morse code transmission. Specifically:
• The line consists only of dashes (“-”), dots (“.”), and slashes (“/”).
• There is at least one character.
• The first and last characters will never be a slash.
• There will never be more than two slashes together.
• Each non-empty sequence between two slashes contains a valid Morse code of one letter.
Output Specification
For each test case, print one line containing the decoded message in uppercase letters.

Sample Input
.-/-.-./–
-.-./-/..-//—/.–././-.
./-/-././-/./.-./.-//-…/.-././…-/../-/-.–//-.-./…./.-/.-../.-.././-./–./.

Output for Sample Input
ACM
CTU OPEN
ETNETERA BREVITY CHALLENGE

题意:26个字母代表不同的符号,/代表一个不同的字母,//代表一个单词之间的空格。这个题可以设成二维数组,每一行只代表一个单词

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
char change[26][5] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
int main()
{
    char s[1100], t[5];
    int slen, i, j, k;
    while(~scanf("%s", s))
    {
        k = 0;
        slen = strlen(s);
        for(i = 0; i < slen; i++)
        {
            if(s[i] == '/')
            {
                t[k] = '\0';
                if(k == 0)
                    printf(" ");
                else for(j = 0; j < 26; j++)
                        if(strcmp(change[j], t) == 0)
                            printf("%c", j+'A');
                k = 0;
            }
            else
            {
                t[k++] = s[i];
            }
        }
        if(k == 0)
            printf(" ");
        else for(j = 0; j < 26; j++)
                if(strcmp(change[j], t) == 0)
                    printf("%c", j+'A');
        printf("\n");
    }
    return 0;
}







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值