Thursday, 4 May 2017

Array - Run Length Decoding

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: "a5br3" Output: "aaaaabrrr" Input: "a10br3a3" Output: "aaaaaaaaaabrrraaa"

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

0 comments:

Post a Comment

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