This document contains the source code of a Java program that takes in a string as input, encodes it by replacing repeated characters with their position in the previous substring and new characters with the next character in an alphabet string, and outputs the encoded string as a BigInteger with the base being the length of the alphabet if it is greater than 1. It contains a main method that reads test cases, encodes the input string for each case using nested for loops, and prints the encoded output.
This document contains the source code of a Java program that takes in a string as input, encodes it by replacing repeated characters with their position in the previous substring and new characters with the next character in an alphabet string, and outputs the encoded string as a BigInteger with the base being the length of the alphabet if it is greater than 1. It contains a main method that reads test cases, encodes the input string for each case using nested for loops, and prints the encoded output.
This document contains the source code of a Java program that takes in a string as input, encodes it by replacing repeated characters with their position in the previous substring and new characters with the next character in an alphabet string, and outputs the encoded string as a BigInteger with the base being the length of the alphabet if it is greater than 1. It contains a main method that reads test cases, encodes the input string for each case using nested for loops, and prints the encoded output.
This document contains the source code of a Java program that takes in a string as input, encodes it by replacing repeated characters with their position in the previous substring and new characters with the next character in an alphabet string, and outputs the encoded string as a BigInteger with the base being the length of the alphabet if it is greater than 1. It contains a main method that reads test cases, encodes the input string for each case using nested for loops, and prints the encoded output.
static final String alpha = new String("1023456789abcdefghijklmnopqrstv");
public static void main(String args[]) { Scanner in = new Scanner(System.in); int cases = in.nextInt(); in.nextLine(); for(int i=1;i<=cases;i++) { // FOR EACH CASE .... String l = in.nextLine(); int next=0,k; String out = new String(); for(int j=0;j<l.length();j++) { char ch = l.charAt(j); if((k=l.substring(0,j).indexOf(ch))>-1) out+=out.charAt(k); // repeated else out+=alpha.charAt(next++); // new digit } System.out.println("Case #"+i+": "+new BigInteger(out,next>1?next:2)); } } }