Skip to content

Instantly share code, notes, and snippets.

@pocari
Last active July 8, 2020 04:42
Show Gist options
  • Save pocari/04d048a3ea8ebebab382dd845eb74044 to your computer and use it in GitHub Desktop.
Save pocari/04d048a3ea8ebebab382dd845eb74044 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
public class Parser {
public static int charToNum(char c) {
if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
}
// 違う場合は全部数字とみなす
return c - '0';
}
public static void main(String... args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Vector<Byte> bytes = new Vector<Byte>();
int c1;
while ((c1 = br.read()) != -1) {
if (c1 == '\\') {
int c2 = br.read();
if (c2 == 'x') {
int b1 = charToNum((char)br.read());
int b2 = charToNum((char)br.read());
bytes.add((byte)(b1 * 16 + b2));
} else {
throw new Exception("error");
}
} else {
bytes.add((byte)c1);
}
}
byte[] byteArray = new byte[bytes.size()];
for (int i = 0; i < byteArray.length; i++) {
byteArray[i] = bytes.get(i).byteValue();
}
System.out.println(new String(byteArray));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment