/* package whatever; // don't place package name! */
import java.util.*;
import java.util.regex.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
String tree
= "(30:0.07,(1:0.06,2:0.76))"; h.put("(1:" , "(30:");
h.put(",1:" , ",30:");
h.put("(30:" , "(6:");
h.put(",30:" , ",6:");
System.
out.
println(convertTree
(tree, h
));
}
Pattern pattern = Pattern.compile("[,(]\\d+:");
Matcher m = pattern.matcher(treeOld);
while (m.find()) {
if (conv.containsKey(m.group(0))) {
m.appendReplacement(result, conv.get(m.group(0)));
}
else {
m.appendReplacement(result, m.group(0));
}
}
m.appendTail(result);
return result.toString();
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS51dGlsLnJlZ2V4Lio7CmltcG9ydCBqYXZhLmxhbmcuKjsKaW1wb3J0IGphdmEuaW8uKjsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJU3RyaW5nIHRyZWUgPSAiKDMwOjAuMDcsKDE6MC4wNiwyOjAuNzYpKSI7CgkJSGFzaE1hcDxTdHJpbmcsIFN0cmluZz4gaCA9IG5ldyBIYXNoTWFwPFN0cmluZywgU3RyaW5nPigpOwoJCWgucHV0KCIoMToiICwgIigzMDoiKTsKCQloLnB1dCgiLDE6IiAsICIsMzA6Iik7CgkJaC5wdXQoIigzMDoiICwgIig2OiIpOwoJCWgucHV0KCIsMzA6IiAsICIsNjoiKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oY29udmVydFRyZWUodHJlZSw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