# Decoding

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

 Sorter: Uncategorized GNYR ICPC 2007 "http://www.acmgnyr.org/year2007/D.pdf"

 This problem has been solved by Mfv2.

This is problem B from the GNYR ICPC 2007

```import java.util.*;
import java.math.*;
import java.io.*;

public class Main {
public static void main(String[] args) throws Exception {
/*Scanner sc = new Scanner(System.in);
int lim = sc.nextInt();
int n = 1;*/
int n = 1;
while (lim-- > 0) {
//int r = sc.nextInt();
//int c = sc.nextInt();
//String in = sc.next();
int r = Integer.parseInt(s[0]);
int c = Integer.parseInt(s[1]);
String o = s[2];

String x = "";
char[][] m = new char[r][c];
char[][] m2 = new char[r][c];
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[0].length; j++) {
m[i][j] = 'X';
}
}
int y= 0;
for (int i = 0; i < m2.length; i++) {
for (int j = 0; j < m2[0].length; j++) {
m2[i][j] = o.charAt(y++);
}
}

//R, D, L, U
//first 3, -0
//next 2, -1
//next 1, -1
//next 1, -1
int i = 0;
int row = 0;
int col = 0;
//System.out.println("r = "  +r + " c = " + c + " o = " + o + " o.length = " + o.length());
String out = "";
wloop:
while (i < o.length()) {
for (; col < c; col++) {
//System.out.println("R col = " + col + " row = "  +row);
if (m[row][col]  != 'X') break;
m[row][col] = o.charAt(i++);
out += m2[row][col];
}
row++;
col--;
for (; row < r; row++) {
//System.out.println("D col = " + col + " row = "  +row);
if (m[row][col]  != 'X') break;
m[row][col] = o.charAt(i++);
out += m2[row][col];

}
col--;
row--;
for (; col >= 0; col--) {
//System.out.println("L col = " + col + " row = "  +row);
if (m[row][col]  != 'X') break;
m[row][col] = o.charAt(i++);
out += m2[row][col];
}
row--;
col++;
for (; row >- 0; row--) {
//System.out.println("U col = " + col + " row = "  +row);
if (m[row][col]  != 'X') break;
m[row][col] = o.charAt(i++);
out += m2[row][col];
}
row++;
col++;
for (int k = 0; k < r; k++) {
for (int j = 0; j < c; j++) {
if (m[k][j] == 'X') continue wloop;
}
}
break;
}

String tmp = "";
System.out.print(n++ + " ");
String outp = "";
for (int k = 1; k <= out.length(); k++) {
tmp += "" + out.charAt(k - 1);
if (k % 5 == 0) {
BigInteger b = new BigInteger(tmp, 2);
int v = b.intValue();
if (v == 0) {
outp +=(" ");
} else {
outp += ((char)('A' + v - 1));
}
//System.out.println("out = " + out + " tmp = " + tmp);
tmp = "";
} else {

}

}
System.out.println(outp.trim());
/*
for (int k = 0; k < r; k++) {
for (int j = 0; j < c; j++) {
System.out.print(m[k][j]);
}
System.out.println();
}
System.out.print(n++ + " ");
for (int k = 0; k < r; k++) {
for (int j = 0; j < c; j++) {
System.out.print(m[k][j]);
}
}
System.out.println();
/*for (int i = 0; i < R + c; i++) {
if (i % 4 == 0) {
for (int j = 0; j < r; j++) {

}
}
}*/
}
}

public static String getb(char a) {
int n = 0;
if (a == ' ')  {
n = 0;
} else {
n = a - 'A' + 1;
}
String o = BigInteger.valueOf((long)n).toString(2);
String x = new String(o);
switch (o.length()) {
case 0: x = "0" + x;
case 1: x = "0" + x;
case 2: x = "0" + x;
case 3: x = "0" + x;
case 4: x = "0" + x;
}
return x;
}
}

```