Cod sursa(job #1360752)

Utilizator diana_ionDiana Ion diana_ion Data 25 februarie 2015 17:37:29
Problema Convertor Scor 90
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.71 kb
#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;


int main()
{

    char ch;
    FILE *input;
    input = fopen("convertor.in", "r");
    ofstream output;
    output.open("convertor.out", ios::out);


    while((ch = fgetc(input)) != '}'){
        if(ch == '\"'){
            ch = fgetc(input);
            while(ch != '\"') {
                output<<ch;
                ch = fgetc(input);
            }
           output<<",";

        }
        else if(ch == ':'){
            ch = fgetc(input);
            while(ch == ' ' || ch == '\n'){
                ch = fgetc(input);
            }
            if ( ch == '"'){
                ch = fgetc(input);
                while(ch != '"'){
                    ch = fgetc(input);
                }
            }
        }

    }
    fclose(input);
    FILE *input2;
    input2 = fopen("convertor.in", "r");
    while((ch = fgetc(input2)) != EOF){

        if(ch == '{')
            output<<"\n";
        else if(ch == ':'){
            ch = fgetc(input2);
            while(ch == ' ' || ch == '\n'){
                ch = fgetc(input2);
            }
            if(isdigit(ch))
                while(ch != ' ' && ch != ',' && ch != '}' && ch != '\n'){
                    output<<ch;
                    ch = fgetc(input2);
                }
            else
                if ( ch == '"'){
                    ch = fgetc(input2);
                    while(ch != '"'){
                        output<<ch;
                        ch = fgetc(input2);
                    }
                }
                output<<",";
        }

    }
    fclose(input2);
    output.close();

    return 0;
}