-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pokechat.cc
72 lines (52 loc) · 1.57 KB
/
Pokechat.cc
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int stringConverter(string);
// start would be i*3;
// characters would be 3;
// string would be the string of code;
string stringExtractor(string, int, int);
int main() {
string word, newWord = "";
string code, codeByteS;
int codeByteI;
getline(cin, word);
cin >> code;
int codeLength = static_cast<int>(code.length());
int loopLength = codeLength/3;
for(int i = 0; i < loopLength; i++) {
codeByteS = stringExtractor(code, i*3, 3);
cout << codeByteS << endl;
codeByteI = stringConverter(codeByteS);
cout << codeByteI << endl;
newWord += word[codeByteI-1];
}
cout << newWord << endl;
}
string stringExtractor(string str, int start, int characters) {
string newStr = "";
for(int i = 0; i < characters; i++) {
newStr += str[start+i];
}
return newStr;
}
int stringConverter(string str) {
int asInt = 0;
for(int i = 0; i < 3; i++) {
int e = pow(10, 3 - (i + 1));
switch(str[i]) {
case '1': asInt += e*1; break;
case '2': asInt += e*2; break;
case '3': asInt += e*3; break;
case '4': asInt += e*4; break;
case '5': asInt += e*5; break;
case '6': asInt += e*6; break;
case '7': asInt += e*7; break;
case '8': asInt += e*8; break;
case '9': asInt += e*9; break;
default: break;
}
}
return asInt;
}