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.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
71 views
A Java
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.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Archivo: /home/misan/gcj/2009/1C/A/A.
java Página 1 de 1
import java.util.*; import java.math.BigInteger;
class A {
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)); } } }