Pagini recente » Cod sursa (job #1360752) | Cod sursa (job #425043) | Cod sursa (job #2616691) | Cod sursa (job #1084400) | Cod sursa (job #1358255)
import java.util.*;
import java.io.*;
public class Convertor1 {
public static void main(String[] args) throws IOException{
BufferedReader input = new BufferedReader( new FileReader("convertor.in"));
BufferedWriter output = new BufferedWriter ( new FileWriter("convertor.out"));
String line = new String();
ArrayList<String> head = new ArrayList<String>();
ArrayList<String> body = new ArrayList<String>();
int lines = 0;
int elements = 0;
StringBuffer sb = new StringBuffer();
while((line = input.readLine()) != null){
for ( int i = 0; i < line.length(); i++){
if(line.charAt(i) == '{')
lines++;
if(line.charAt(i) == ':') {
if(lines == 1){
head.add(sb.toString());
elements++;
}
sb = new StringBuffer();
i++;
while(line.charAt(i) == ' ')
i++;
if(line.charAt(i) == '\"'){
i++;
while(line.charAt(i) != '\"'){
sb.append(line.charAt(i));
i++;
}
body.add(sb.toString());
sb = new StringBuffer();
if ( i < line.length() )
i++;
}
if(Character.isDigit(line.charAt(i))){
sb.append(line.charAt(i));
i++;
while(line.charAt(i) != ' ' && line.charAt(i) != ',' && line.charAt(i) != '}'){
sb.append(line.charAt(i));
i++;
}
body.add(sb.toString());
sb = new StringBuffer();
}
}
if(line.charAt(i) == '\"'){
i++;
while(line.charAt(i) != '\"'){
sb.append(line.charAt(i));
i++;
}
}
}
}
for(int i = 0; i < elements; i++){
output.write(head.get(i));
output.write(",");
}
output.newLine();
for(int j = 0; j < lines; j++ ){
for(int i = 0; i < elements; i++){
output.write(body.get(elements * j + i));
output.write(",");
}
output.newLine();
}
input.close();
output.close();
}
}