Cod sursa(job #1361596)

Utilizator RoxanaCptCapitanu Roxana - Steliana RoxanaCpt Data 25 februarie 2015 22:24:06
Problema Convertor Scor 70
Compilator java Status done
Runda rosedu_cdl_2015 Marime 1.68 kb

import java.io.*;
import java.util.*;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Roxana Capitanu
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        String allText = "", line;
        String[] aux;
        BufferedReader br;
        BufferedWriter bw;

        br = new BufferedReader(new FileReader("convertor.in"));
        bw = new BufferedWriter(new FileWriter("convertor.out"));

        //citesc datele din fisier
        while ((line = br.readLine()) != null) {
            allText += line;
        }

   //parsez cheile din cadrul fisierului de input si le scriu in fisierul
        //de output
        for (String s : allText.split("}")[0].split(",")) {
            bw.write(s.split(":")[0].split("\"")[1] + ",");
        }
        bw.newLine();
    //parsez valorile din cadrul fisierului de input si le scriu in fisierul
        //de output
        for (String str : allText.split("}")) {
            for (String s : str.split(",")) {
                aux = s.split(":");
                if (aux.length > 1) {
                    if (aux[1].split("\"").length > 1) {
                        bw.write(aux[1].split("\"")[1] + ",");
                    } else {
                        bw.write(aux[1].replaceAll(" ", "").replaceAll(",", "") + ",");
                    }
                }
            }
            bw.newLine();
        }
        br.close();
        bw.close();

    }

}