//Removing a zero(0) after a series of 5 consecutive one's(1)
import java.util.*;
class BitDestuffing
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int []arr=new int[20];
int cnt=0;
int m=0;
System.out.print("Enter string length: ");
int a=input.nextInt();
System.out .print("Enter a string: ");
for(int i=0;i<a;i++)
{
arr[i]=input.nextInt();
}
for(int i=0;i<a;i++)
{
if(arr[i]==1)
cnt++;
else
cnt=0;
if(cnt==5)
{
if(arr[i+1]==0)
i=i++;
m=i+1;
cnt=0;
}
}
System.out.println("Your String is:");
for(int i=0;i<a;i++)
{
if(i==m)
{}
else
System.out.print(arr[i]);
}
}
}
import java.util.*;
class BitDestuffing
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int []arr=new int[20];
int cnt=0;
int m=0;
System.out.print("Enter string length: ");
int a=input.nextInt();
System.out .print("Enter a string: ");
for(int i=0;i<a;i++)
{
arr[i]=input.nextInt();
}
for(int i=0;i<a;i++)
{
if(arr[i]==1)
cnt++;
else
cnt=0;
if(cnt==5)
{
if(arr[i+1]==0)
i=i++;
m=i+1;
cnt=0;
}
}
System.out.println("Your String is:");
for(int i=0;i<a;i++)
{
if(i==m)
{}
else
System.out.print(arr[i]);
}
}
}
No comments:
Post a Comment