-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunny.cpp
39 lines (33 loc) · 960 Bytes
/
funny.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
32
33
34
35
36
37
38
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
void stringzip(const char* str, int str_size, char* zipped_str)
{
char curr_char, saved_char = *str;
int counter=0;
for(int i=0; i<str_size+1;i++)
{
curr_char = str[i];
if(curr_char == saved_char)
counter++;
else
{
_itoa(counter,zipped_str, 10);
zipped_str+= strlen(zipped_str);
*zipped_str=saved_char;
zipped_str++;
counter = 1;
saved_char = curr_char;
}
}
}
void main()
{
const char *pInputStr="xxxyyyeeeellllllllddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddkkkkkkkkkkkkzzzzzzzzzzzzdddddddddgggggggzza";
long lInputLen=strlen(pInputStr);
char *pOutputStr=new char[1000]();
stringzip(pInputStr,lInputLen,pOutputStr);
printf("%s",pOutputStr);
delete []pOutputStr;
}