-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip.cpp
More file actions
46 lines (46 loc) · 1.16 KB
/
Copy pathzip.cpp
File metadata and controls
46 lines (46 loc) · 1.16 KB
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
#include<iostream>
using namespace std;
string zipString(string iniString){
// write code here
int length = iniString.size();
if(length == 0)
return "";
int i = 0;
int j = 0;
string str;
while(i < length) {
while(i < length && iniString[i] == iniString[j])
i++;
str += iniString[j];
str += to_string(i-j);
j=i; }
if(str.size() >= length)
return iniString;
else
return str;
return iniString;}
string unzipString(String decodestring){
int length = decodestring.size();
if(length == 0)
return "";
int i = 0;
int j = 0;
string str;
while(i < length) {
while(i < length && decodestring[i] >'0' &&decodestring[i] < '9')
str += decodestring[j];
i++;
str += to_string(i-j);
j=i; }
if(str.size() >= length)
return iniString;
else
return str;
return iniString;}
int main(){
string str;
while(cin>>str){
cout << zipString(str) << endl;
}
return 0;
}