Run length encoding in C++

#include<conio.h>
#include<iostream.h>
#include<string.h>
void main()
{
 clrscr();
 char str[10];
 cout<<"\n Enter the word: ";
 cin>>str;
 cout<<"\n After Run length encoding: \n";
 int count=1;
 for(int i=0;i<strlen(str);i++)
 {
    if(str[i]==str[i+1])
    {
     count+=1;
    }
    else
    {
     if(count==1)
     {
      cout<<str[i];
     }
     else
     {
       cout<<str[i]<<count;
       count=1;
     }
    }
 }
 getch();
}

Comments

Popular posts from this blog

Windows Form app to Convert YouTube videos to MP3 instantly

Silde show of images In JSP

Working with database in Vb.net