Last active
July 8, 2020 04:42
-
-
Save pocari/04d048a3ea8ebebab382dd845eb74044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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