I made this python script with another guy a year ago
How do you make a dictionary in C++? And how do I make this script in the same format for a C++ program? I've tried in a very unethical and unlogical manner :P
Code:
### This is a dictionary...
MyDict={'a':'$','b':'i','c':'q','d':'s','e':'w','f':'~','g':'d','h':'2',
'i':'5','j':'6','k':'a','l':'g','m':'-','n':'j','o':'z','p':'%',
'q':'h','r':'9','s':'f','t':'7','u':'+','v':'c','w':'0','x':'8',
'y':'/','z':'x',' ':'*'}
## This is just to show the mapping of the 'encoding'
for k,v in MyDict.iteritems():
print k,' will be encoded to.. ',v
## Here we ask for the word to be encoded
## Notice that i use the '.lower' method in case
## the user inserts any uppercase letters
Word=raw_input("What is the word you want to encode?").lower()
## This is an empty string to begin with
Encoded_Word=''
## Now we iterate over the inserted word to check each letter
for letter in Word:
if MyDict.has_key(letter):
## Insert to the string the coresponding character..
Encoded_Word=Encoded_Word+MyDict.get(letter)
## Print the encoded word
print Encoded_Word
Code:
//Encoder
#include <iostream>
using namespace std;
int main()
{
int A1;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
int h;
int i;
int j;
int k;
int l;
int m;
int n;
int o;
int p;
int q;
int r;
int s;
int t;
int u;
int v;
int w;
int x;
int y;
int z;
int A3;
system("cls");
cout << "--------------------------------------------------------------------------------";
cout << "Encoder";
cout << "\n--------------------------------------------------------------------------------";
\u0020 = "*"
a = "$"
b = "i";
c = "q";
d = "s";
e = "w";
f = "~";
g = "d";
h = "2";
i = '5";
j = "6";
k = "a";
l = "g";
m = "-";
n = "j";
o = "z";
p = "%";
q = "h";
r = "9";
s = "f";
t = "7";
u = "+";
v = "c";
w = "0";
x = "8";
y = "/";
z = "x";
cout << "What is the word you want to encode?";
cin >> A1
A3 = A1 +
cout << A1;
cout << "\n--------------------------------------------------------------------------------";
cout << "Bye";
cout << "\n--------------------------------------------------------------------------------";
return 0;
}
Comment