I made a C ++ program that converts a morse code to letters.
However, this program will receive up to 1000 characters. But I do not know what happens, it at most receives 400 characters, and then the console hangs .
What happens?
Follow the code below:
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
string convertMorse(string s) {
cout<<s<<endl;
if(s=="=.===")return "a";
if(s=="===.=.=.=")return "b";
if(s=="===.=.===.=")return "c";
if(s=="===.=.=")return "d";
if(s=="=")return "e";
if(s=="=.=.===.=")return "f";
if(s=="===.===.=")return "g";
if(s=="=.=.=.=")return "h";
if(s=="=.=")return "i";
if(s=="=.===.===.===")return "j";
if(s=="===.=.===")return "k";
if(s=="=.===.=.=")return "l";
if(s=="===.===")return "m";
if(s=="===.=")return "n";
if(s=="===.===.===")return "o";
if(s=="=.===.===.=")return "p";
if(s=="===.===.=.===")return "q";
if(s=="=.===.=")return "r";
if(s=="=.=.=")return "s";
if(s=="===")return "t";
if(s=="=.=.===")return "u";
if(s=="=.=.=.===")return "v";
if(s=="=.===.===")return "w";
if(s=="===.=.=.===")return "x";
if(s=="===.=.===.===")return "y";
if(s=="===.===.=.=")return "z";
return "lixo";
}
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t; cin>>t;
string str;
string saida;
while(t--) {
cin>>str;
string nova;
int contap = 0;
for(int i=0;i<str.size();++i) {
if(str[i]=='=') {
if(contap==3) {
// cout<<"n: "<<nova<<endl;
saida += convertMorse(nova);
contap=0; nova.clear();
}
if(contap==7) {
saida+=convertMorse(nova);
saida+=' ';
nova.clear();
contap=0;
}
while(contap>0) {
contap--; nova+='.';
}
nova+=str[i];
} else {
contap++;
}
}
saida+=convertMorse(nova);
cout<<saida<<endl;
saida.clear();
}
return 0;
}