莫尔斯美元的C C $ D转换器 [英] Morse Code Converter in C

查看:316
本文介绍了莫尔斯美元的C C $ D转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是功课
我们假设有字符二维数组持有255字符的大小限制字符字符字符串[100] [255];

程序neede:由用户更改拼音输入莫尔斯code /英文字母(大写)

Program neede: change the input morse code by a user to alphabet/English letter (Capital Letters)

采样输入

2

 .... . .-.. .-.. --- / .-- --- .-. .-.. -..

 .--- --- -.- .

示例输出


  • 案例#1:

  • Case#1:

HELLO WORLD


  • 案例#2:

  • Case#2:

    JOKE
    


  • 我的唯一的想法是为具有由用户inputed一个字的第一个字符..要..如果选中'。或' - ',然后小心翼翼地和手动分配..嵌套的在(string [I] [C] =='')最后,如果每个嵌套会在(string [I] [C] =='')然后打印出字母E的例子

    My only idea is to have the first characters of a word that is inputed by the user.. to be.. checked if its '.' or '-' then scrupulously and manually assigning.. the nested if(string[i][c]=='.') and the last if on each nested would be if(string[i][c]==' ') then that prints out the letter "E" example

    if(string[i][c]=='.') {
        isspace(string[i][c+1])
        printf("E");
    }
    

    现在我的问题是..有这个问题的更简单的方法?在这里我不必键入相同的' - '和'。' if语句..之类的东西?并有我的脑海里爆炸?因为我失去了相应的跟踪与if或case语句的下一个字符的?

    Now my question is.. is there any easier way for this problem? where i don't have to type the same '-' and '.' if statement.. and stuff? and have my mind explode? because I lose track of corresponding the next char with if or case statements?

    推荐答案

    您已经发现,可以在每个莫尔斯信号,这是烦人硬code支线全部为如果 - 其他语句。当你这样做了,你会注意到一定的结构与更深的嵌套条件。您可以重新present这种结构树:

    You have already discovered that you can branch on each morse signal and that it is tiresome to hard-code all that as if-else statements. When you have done so, you will have noted a certain structure with ever deeper nested conditions. You can represent this structure as a tree:

                           *
                       /       \
                   E               T
                 /   \           /   \
               I       A       N       M
              / \     / \     / \     / \ 
             S   U   R   W   D   K   G   O
            / \ / \ / \ / \ / \ / \ / \ / \ 
            H V F * L * P J B X C Y Z Q * *
    

    这是同一棵树可以在(略)prettier在形式找到在莫尔斯code 的维基百科条目的中间部分。 (最低行中的星号表示没有英语字母表的26个字母中的一个编码。)

    That same tree can be found in a (slightly) prettier form in the middle sections of the Wikipedia entry on Morse code. (The asterisks in the lowest row indicate encodings that are not one of the 26 letters of the English alphabet.)

    您从顶部开始。科留在DIT,分支机构对上一大新和阅读的价值,当你完成。

    You start at the top. Branch left on a dit, branch right on a dah and read the value when you are done.

    有实现的树木很多方面。在这种情况下,该树的分支都是相同的深度,至少如果我们考虑在星号,太。可以通过索引节点在行重新present树作为线性阵列。当脚趾顶端节点是1,您可以:

    There are many ways to implement trees. In this case, the tree's branches are all of the same depth, at least if we consider the asterisks, too. You can represent the tree as a linear array by indexing the nodes row-wise. When toe top node is 1, you get:

                           1
                       /       \
                   2               3
                 /   \           /   \
               4       5       6       7
              / \     / \     / \     / \ 
             8   9  10  11  12  13  14  15
            / \ / \ / \ / \ / \ / \ / \ / \
           16 ...                     ... 31
    

    您可以看到分支从节点离开 N 带你到节点 2 * N 和分支右带给你其与指数权邻居 2 * N + 1 。建立,当您去,从1开始,然后查找你信中的数组索引:

    You can see that branching left from node n brings you to node 2*n and branching right brings you to its right neighbour with index 2*n + 1. Build up the index as you go, starting from 1 and then look up your letter in the array:

    const char *letter = "**ETIANMSURWDKGOHVF?L?PJBXCYZQ??";
    

    (在前面的两个星号表示非法指数。)

    (The two asterisks at the front indicate illegal indices.)

    这篇关于莫尔斯美元的C C $ D转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆