Cod sursa(job #1360643)

Utilizator silvia_the_bestSilvia Pripoae silvia_the_best Data 25 februarie 2015 17:00:47
Problema Convertor Scor 100
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> elements;
	string str;
	char c;
	int H, fline, i;

	freopen(FIN, "r", stdin);
	freopen(FOUT, "w", stdout);

	for (fline = 1; ; )
	{
		c = getchar();
		if (c < 33)
			continue;

		if (c == '"')
		{
			for (str.clear(), c = getchar(); c != '"'; c = getchar())
				str.push_back(c);

			if (fline)
			{
				fputs(str.c_str(), stdout);
				putchar(',');
			}
		}
		if (c == ':')
		{
			for (c = getchar(); c < 33; c = getchar());

			if (c == '"')
				for (str.clear(), c = getchar(); c != '"'; c = getchar())
					str.push_back(c);
			else
				for (str.clear(); c >= '0' && c <= '9'; c = getchar())
					str.push_back(c);

			if (fline)
				elements.push_back(str);
			else
			{
				fputs(str.c_str(), stdout);
				putchar(',');
			}
		}
		if (c == '}' && fline)
		{
			fline = 0;
			H = elements.size();
			putchar('\n');
			for (i = 0; i < H; ++ i)
			{
				fputs(elements[i].c_str(), stdout);
				putchar(',');
			}
		}
		if (c == '{' && !fline)
			putchar('\n');
		if (c == ']')
			break;
	}

	putchar('\n');
}