Thursday, 4 May 2017

Array - Run Length Encoding

public String func (String str){
// write your code here
if(str==null)
{
    return null;
}
String output="";
String l="";
char dh;
int i,j=0,k,c=0,p=0,m=str.length();
for(i=0;i<m;i++){
    if(str.charAt(i)>='0' && str.charAt(i)<='9'){
        c++;
        if(c==1)
        j=i-1;
        l=l+str.charAt(i);
        p=Integer.valueOf(l);
        continue;
         }
         else
         if(p==0)
         output=output+str.charAt(i);
        if(p!=0){
            for(k=1;k<p;k++)
            output=output+str.charAt(j);
            i--;}
            p=0;c=0;l="";
}
if(p!=0){
    for(i=1;i<p;i++)
    output=output+str.charAt(j);
}
        return output;
   

    }
}

Input: "aaaaabrrr" Output: "a5br3" Input: "aaaaaaaaaabrrraaa" Output: "a10br3a3"

Visit : https://c-programs-world.blogspot.in for more question

Related Posts:

  • Array - Split reverse   Given a string (array of character), split the string to half and reverse each half Input: Input String: "Mike" Output: "iMek" Input String… Read More
  • Pangrams Pangrams are sentences constructed by using every letter of the alphabet at least once. #include<stdio.h> #include<string.h> #include&l… Read More
  • Circular Array Rotation Right Circular Array Rotation   Given a String rotate the array by given number 'n' #include <math.h> #include <stdio.h> int ma… Read More
  • Array - Run Length Decoding public String func (String str){ // write your code here if(str==null) {     return null; } String output=""; String l=""; char dh; in… Read More
  • Array - Run Length Encoding public String func (String str){ // write your code here if(str==null) {     return null; } String output=""; String l=""; char dh; in… Read More

1 comment:

  1. Make Money at Casino.com | Bet On What You Will Win
    The online casino industry 인카지노 has the best payouts and offers on หาเงินออนไลน์ the market. casino.com bonuses and promotions and have several 메리트 카지노 고객센터 ways to win.

    ReplyDelete

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages

Blog Archive

Powered by Blogger.

Sample Text

Array - Shuffle merge

  Given a input two string (inputStr1) and (inputStr2), merge these two string by combining elements of same index Input String: "He...

Followers

Search This Blog

Ordered List

Theme Support