Cod sursa(job #1360036)

Utilizator silvia_the_bestSilvia Pripoae silvia_the_best Data 25 februarie 2015 11:01:59
Problema Convertor Scor 90
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.47 kb
#include <cstdio>
#include <string>
#include <vector>
 
#pragma optimize("s", on)
 
using namespace std;
 
#define FIN "convertor.in"
#define FOUT "convertor.out"
 
int main()
{
    vector <string> elements;
    string str;
    char c;
    int H, fline, i;
 
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
 
    for (fline = 1; scanf("%c", &c); )
    {
        if (c < 33)
            continue;
         
        if (c == '"')
        {
            for (str.clear(), scanf("%c", &c); c != '"'; scanf("%c", &c))
                str.push_back(c);
         
            if (fline)
                printf("%s,", str.c_str());
        }
        if (c == ':')
        {
            for (scanf("%c", &c); c < 33; scanf("%c", &c));
 
            if (c == '"')
                for (str.clear(), scanf("%c", &c); c != '"'; scanf("%c", &c))
                    str.push_back(c);
            else
                for (str.clear(); c >= '0' && c <= '9'; scanf("%c", &c))
                    str.push_back(c);
 
            if (fline)
                elements.push_back(str);
            else
                printf("%s,", str.c_str());
        }
        if (c == '}' && fline)
        {
            fline = 0;
            H = elements.size();
            printf("\n");
            for (i = 0; i < H; ++ i)
                printf("%s,", elements[i].c_str());
        }
        if (c == '{' && !fline)
            printf("\n");
        if (c == ']')
            break;
    }
     
    printf("\n");
}