-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeToString.cpp
42 lines (41 loc) · 953 Bytes
/
codeToString.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
using namespace std;
int main(){
unordered_map<string,char> mp;
ifstream code;
string temp,temp2;
code.open("morseCode.txt");
for(int i=0 ; i<26 ; i++){
getline(code,temp);
mp[temp]='a'+i;
}
for(int i=26 ; i<36 ; i++){
getline(code,temp);
mp[temp]='0'+i;
}
code.close();
cout<<"Enter a code to convert to string :\n";
getline(cin,temp);
int n=temp.size();
string ans="";
for(int i=0 ; i<n ; i++){
if(temp[i]=='0'&&temp[i+1]=='0'){
ans+=mp[temp2];
if(temp[i+5]=='0'){
ans+=' ';
i+=6;
}else{
i+=2;
}
temp2.clear();
continue;
}
temp2+=temp[i];
}
ans+=mp[temp2];
cout<<ans;
return 0;
}