Skip to content

Instantly share code, notes, and snippets.

@maheshmc2
Created April 1, 2011 01:32
Show Gist options
  • Save maheshmc2/897596 to your computer and use it in GitHub Desktop.
Save maheshmc2/897596 to your computer and use it in GitHub Desktop.
public class Gp4 {
public static void main(String... args ){
java.util.Scanner read = new java.util.Scanner(System.in);
System.out.println("Number of Lines are: ");
int no = read.nextInt();
String[] input = new String[no];
for(int i=0; i<no ; ){
// System.out.println("Enter for i = "+i);
input[i] = read.next();
i = i+1;
}
int k = 3;
processInput(input, k);
}
private static void processInput(String[] ip, int k){
String[] temp = null;
for(int i=0 ; i<ip.length ; ++i){
if(i%k == 0){
temp = new String[k];
}
temp[i%k] = ip[i];
if(i%k == k-1)
processBlock(temp);
}
}
private static void processBlock(String[] block){
if(block == null || block.length == 0)
return;
String line1 = block[0];
System.out.println("Block Encoding Started");
// System.out.println(block[0]);
for(int i=1; i<block.length ; ++i){
processLines(block[i-1], block[i]);
}
System.out.println("Block Encoding Ends");
}
private static void processLines(String ref, String line){
// System.out.println("Ref is: "+ref+"\n Line is: "+line);
String temp="";
for(int i=0 ; i<ref.length() ; ++i){
if(ref.charAt(i) == line.charAt(i))
temp = temp + "0";
else
temp = temp + "1";
}
char current = temp.charAt(0);
int count = 0;
for(int i=0 ; i<temp.length() ; ++i){
if(temp.charAt(i) == current)
++count;
else{
System.out.print(" "+current + " " + count);
current = temp.charAt(i);
count = 1;
}
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment