Pagini recente » Cod sursa (job #2572440) | Cod sursa (job #1519707) | Cod sursa (job #1188285) | Cod sursa (job #2474816) | Cod sursa (job #1361040)
import java.io.*;
import java.util.Scanner;
import java.util.regex.*;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileInputStream("convertor.in"));
sc.useDelimiter("}\\s*,");
// Lista are mai multe obiecte
// Un obiect are mai multe intrari
// O intrare are o pereche cheie-valoare
// Declarari si initializari
String obj;
String[] entries;
String key = "";
String value;
Pattern patternKey = Pattern.compile("\"([^\"\\(\\)]+)\"");
StringBuilder sb = new StringBuilder(1024000);
boolean first = true;
while (sc.hasNext()) {
obj = sc.next();
entries = obj.split("\\s*,\\s*");
if (first) {
for (String entry : entries) {
String[] entry2 = entry.split("\\s*:\\s*");
try {
Matcher matcher = patternKey.matcher(entry2[0]);
matcher.find();
key = matcher.group(0).replaceAll("\"", "");
} catch (IllegalStateException e) {}
//System.out.print(key + ",");
sb.append(key + ",");
}
first = false;
}
//System.out.println();
sb.append("\n");
for (String entry : entries) {
value = entry.substring(entry.indexOf(':') + 1);
value = value.replaceAll("[\"}\\]]", "").trim();
//System.out.print(value + ",");
sb.append(value + ",");
}
}
PrintWriter writer = new PrintWriter("convertor.out");
writer.write(sb.toString());
writer.close();
sc.close();
}
}