英语翻译就是能把字母,数字,符号用“.”“-”互译的以字母与字母之间隔一个空格,单词与单词之间隔三个空格的方式输入来翻译

1个回答

  • 输入摩斯电码 翻译出 英文,只能识别英文字母,字母间隔一个空格,单词间隔三个空格 输入摩斯电码

    #include "stdio.h"

    #include "conio.h"

    #include "string.h"

    int morseindex(const char *a);

    int main(void)

    {

    int i,j,space;

    char *p;

    char buffer[1024];

    char a[6];

    gets(buffer);

    p = buffer;

    i = 0;

    space = 0;

    while(1)

    {

    if (*p == 32 || *p == ' ')

    {

    a[i] = ' ';

    if (strlen(a) != 0)

    {

    j = morseindex(a);

    if (j >= 0)

    printf("%c",'a' + j);

    }

    i = 0;

    space++;

    if (space == 3)

    printf(" ");

    }

    else

    {

    a[i++] = *p;

    space = 0;

    }

    if (*p == ' ')

    break;

    p++;

    }

    }

    int morseindex(const char *a)

    {

    int i;

    static char morsetable[26][5] = {{".-"},{"-..."},{"-.-."},{"-.."},{"."},{"..-."},{"--."},{"."},{".."},{".---"},{"-.-"},{".-.."},{"--"},{"-."},{"---"},{".--."},{"--.-"},{".-."},{"..."},{"-"},{"..-"},{"...-"},{".--"},{"-..-"},{"-.--"},{"--.."}};

    for (i = 0; i < 26; i++)

    {

    if (strcmp(a,morsetable[i]) == 0)

    {

    return i;

    }

    }

    return -1;

    }