-
Notifications
You must be signed in to change notification settings - Fork 0
/
VowelCode.cpp
31 lines (28 loc) · 886 Bytes
/
VowelCode.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
#include <string>
#include <algorithm>
#include <iostream>
std::string encode(const std::string &str)
{
std::string str1 = str;
std::replace(str1.begin(), str1.end(), 'a', '1');
std::replace(str1.begin(), str1.end(), 'e', '2');
std::replace(str1.begin(), str1.end(), 'i', '3');
std::replace(str1.begin(), str1.end(), 'o', '4');
std::replace(str1.begin(), str1.end(), 'u', '5');
return str1;
}
std::string decode(const std::string &str)
{
std::string str1 = str;
std::replace(str1.begin(), str1.end(), '1', 'a');
std::replace(str1.begin(), str1.end(), '2', 'e');
std::replace(str1.begin(), str1.end(), '3', 'i');
std::replace(str1.begin(), str1.end(), '4', 'o');
std::replace(str1.begin(), str1.end(), '5', 'u');
return str1;
}
int main()
{
std::cout << encode("aeiouhg") << std::endl;
std::cout << decode("12345678");
}