Cod sursa(job #1357724)

Utilizator edigiorgiEdi Georgi edigiorgi Data 24 februarie 2015 02:39:02
Problema Convertor Scor 80
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 2.65 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>

using namespace std;

int main()
{
	ifstream f("convertor.in");
	ofstream g("convertor.out");
	string s;
	char c;
	int cont2 = 0;
	f >> c;
	while (c != '}')
	{
		if (c == '"')
		{
			cont2 = (cont2 + 1) % 2;
			if (cont2)
			{
				char x;
				f.get(x);
				do
				{
					g << x;
					f.get(x);
				} while (x != '"');
				g << ',';


				/*
				string s;
				f >> s;
				while (s.find("\"") == string::npos)
				{
					int spatii = -1;
					char x;
					do
					{
						f.get(x);
						spatii++;
					} while (x == ' ');
					string y (spatii, ' ');
					s += y + x;
					f >> y;
					s += y;
				}

				char x;
				do
				{
					x = s.back();
					s.pop_back();
				} while (x != '"');

				g << s << ',';
				*/
			}
			else
			{
				string s;
				f >> s;
				while (s.find("\"") == string::npos)
				{
					f >> s;
				}
				if (s.find("}") != string::npos)
					break;
			}

		}
		else if (((c - '0') < 10) && (c - '0' >= 0))
		{
			cont2++;
			string s;
			f >> s;
			if (s[s.size() - 1] == '}')
				break;
		}
		f >> c;
	}
	g << endl;
	f.clear();
	f.seekg(0);
	f >> c;
	do
	{
		if (c == '{')
		{
			cont2 = 0;
			while (c != '}')
			{
				if (c == '"')
				{
					cont2 = (cont2 + 1) % 2;
					if (cont2 == 0)
					{
						char x;
						f.get(x);
						do
						{
							g << x;
							f.get(x);
						} while (x != '"');
						g << ',';
						/*
						string s;
						f >> s;
						int e = 0;
						while (s.find("\"") == string::npos)
						{
							int spatii = -1;
							char x;
							do
							{
								f.get(x);
								spatii++;
							} while (x == ' ');
							string y (spatii, ' ');
							s += y + x;
							f >> y;
							s += y;
						}
						
						if (s.find("}") != string::npos)
							e = 1;
						char x;
						do
						{
							x = s.back();
							s.pop_back();
						} while (x != '"');
						g << s << ',';
						if (e)
							break;
						*/
					}
					else
					{
						string s;
						f >> s;
						while (s.find("\"") == string::npos)
						{
							f >> s;
						}
					}

				}
				else if (((c - '0') < 10) && (c - '0' >= 0))
				{
					cont2 = (cont2 + 1) % 2;
					if (cont2 == 0)
					{
						string s;
						f >> s;
						while (((s.back() - '0') > 9) || (s.back() - '0' < 0))
						{
							s.pop_back();
						}
						g << c << s << ',';
					}
					else
					{
						string s;
						f >> s;
					}
				}
				f >> c;
			}
			g << endl;
		}
		f >> c;
	} while (!f.eof());
	f.close();
	g.close();
	return 0;
}