Cod sursa(job #1340837)

Utilizator silvia_the_bestSilvia Pripoae silvia_the_best Data 12 februarie 2015 05:25:58
Problema Convertor Scor 90
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.15 kb
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

#define FIN "convertor.in"
#define FOUT "convertor.out"

int main()
{
	vector <string> headers, 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)
				headers.push_back(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 = headers.size();
			for (i = 0; i < H; ++ i)
				printf("%s,", headers[i].c_str());
			printf("\n");
			for (i = 0; i < H; ++ i)
				printf("%s,", elements[i].c_str());
		}
		if (c == '{' && !fline)
			printf("\n");
		if (c == ']')
			break;
	}
	
	printf("\n");
}