-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecoder.cpp
More file actions
38 lines (31 loc) · 795 Bytes
/
Decoder.cpp
File metadata and controls
38 lines (31 loc) · 795 Bytes
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
#include <iostream>
#include <string>
using namespace std;
int main() //Converts the encoded text into the original message
{
string output;
string text;
cout<<"Inserisci codice compatto: \n";
cin>>text;
text = text + "|";
int size = text.size();
int num = 0;
char carattere;
bool status = true; //true quando deve vedere un carattere
for (int i=0; i<size; i++) {
if (status){
carattere = text[i];
status = false;
} else if (text[i] != '|') {
num = num*10 + (text[i] - '0');
} else {
for (int j=0; j<num; j++){
output += carattere;
}
status = true;
num = 0;
}
}
cout<<output;
return 0;
}