我有这个代码试图将莫尔斯代码翻译成字母:
#include <stdio.h>
#include <string.h>
#define BSIZE 15
char *morseToLetter(char *);
int main() {
char *morseCode = ".... . .-.. .-.. --- / -.. .- .. .-.. -.-- / .--. .-. --- --. .-. .- -- -- . .-. / --. --- --- -.. / .-.. ..- -.-. -.- / --- -. / - .... . / -.-. .... .- .-.. .-.. . -. --. . ... / - --- -.. .- -.--";
char buffer[BSIZE] = { 0 };
int …Run Code Online (Sandbox Code Playgroud) public class MorseCodeTranslator {
public static void main(String[] args) {
String [] letter = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
String [] morse = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--..", …Run Code Online (Sandbox Code Playgroud) 我正在尝试清除 JTextArea 中的文本,并查看其他问题,似乎调用 textArea.setText(""/null) 将清除文本区域。我的代码似乎没有发生这种情况,它将新文本附加到该区域中已有的文本中。有人能看出我的代码有什么问题吗?
public class morseJFrame extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
public JTextPane textPane = new JTextPane();
public JTextArea textArea = new JTextArea();
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
morseJFrame frame = new morseJFrame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public morseJFrame() …Run Code Online (Sandbox Code Playgroud) 我正在写一个小函数,它检查输入的字符串是否是莫尔斯码.该函数应该执行类似"If" - "或"的操作."仅在Inputted_string中:"但我似乎无法找到在Python3上执行唯一操作的方法.我实现这一目前的方式是非常混乱,而不是非常Pythonic
if "-" in message:
# message might be morse code so check even more
if "." in message:
# Message IS morse code so return true
return True
else:
# TODO you can use a REGEX for the below things
if '--' in message:
# if the messsage contains only hyphens, then check to see if
# message contans hyphen only morse code by checking all hyphen
# only morse code against message
return True …Run Code Online (Sandbox Code Playgroud) 莫尔斯电码是最便宜和最流行的消息通信方式。在摩尔斯电码中,字母表中的每个字母都由一系列点和破折号表示。传统上,点由一个短音符传输,破折号由一个较长的音符传输,不同字母之间有停顿。英文字母的每个字母的摩尔斯电码表示如下
a .-
b -...
c -.-.
d -..
e .
f ..-.
g --.
h ....
i ..
j .---
k -.-
l .-..
m --
n -.
o ---
p .--.
q --.-
r .-.
s ...
t -
u ..-
v ...-
w .--
x -..-
y -.--
z --..
Run Code Online (Sandbox Code Playgroud)
例如,让消息是-..-----.并且它由三个字母组成,它可能表示 njg、dog、xmg 或 xon。
我想知道算法。据我所知,我们可以让 HashMap 将键作为点或线,并将值作为字母。但是现在我无法考虑如何检查形成的每个不同的单词。也许递归或动态编程可以做到这一点,但请给我算法,以便我可以开始编码。