b385.
摩斯電碼的秘密
| From: [192.168.120.33] |
Post Date
:
2025-04-15 18:43
#include <iostream>
#include <string>
#include <unordered_map>
#include <sstream>
#include <vector>
using namespace std;
int main() {
unordered_map<string, char> morseToDigit = {
{"-----", '0'},
{".----", '1'},
{"..---", '2'},
{"...--", '3'},
{"....-", '4'},
{".....", '5'},
{"-....", '6'},
{"--...", '7'},
{"---..", '8'},
{"----.", '9'}
};
string input;
getline(cin, input);
istringstream iss(input);
string morseCode;
string result;
while (iss >> morseCode) {
if (morseToDigit.find(morseCode) != morseToDigit.end()) {
result += morseToDigit[morseCode];
}
}
cout << result << endl;
return 0;
}