Cod sursa(job #1357733)

Utilizator edigiorgiEdi Georgi edigiorgi Data 24 februarie 2015 03:02:44
Problema Convertor Scor 80
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.67 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.get(c);
	while (c != '}')
	{
		if (c == '"')
		{
			cont2 = (cont2 + 1) % 2;
			if (cont2)
			{
				char x;
				f.get(x);
				while (x != '"')
				{
					g << x;
					f.get(x);
				} 
				g << ',';

			}
			else
			{
				char x;
				do
				{
					f.get(x);
				} while (x != '"');
			}

		}
		else if (((c - '0') < 10) && (c - '0' >= 0))
		{
			cont2 = (cont2 + 1) % 2;
			char x;
			do
			{
				f.get(x);
			} while ((x - '0' >= 0) && ('9' - x < 10));
		}
		f.get(c);
	}
	g << endl;
	f.clear();
	f.seekg(0);
	
	while (f.get(c))
	{
		if (c == '{')
		{
			cont2 = 0;
			while (c != '}')
			{
				if (c == '"')
				{
					cont2 = (cont2 + 1) % 2;
					if (cont2 == 0)
					{
						char x;
						f.get(x);
						while (x != '"')
						{
							g << x;
							f.get(x);
						}
						g << ',';

					}
					else
					{
						char x;
						do
						{
							f.get(x);
						} while (x != '"');
					}

				}
				else if (((c - '0') < 10) && (c - '0' >= 0))
				{
					cont2 = (cont2 + 1) % 2;
					if (cont2 == 0)
					{
						g << c;
						char x;
						f.get(x);
						while ((x - '0' >= 0) && ('9' - x < 10))
						{
							g << x;
							f.get(x);
						}
						g << ',';
					}
					else
					{
						char x;
						do
						{
							f.get(x);
						} while ((x - '0' >= 0) && ('9' - x < 10));
					}
				}
				f.get(c);
			}
			g << endl;
		}
	}
	f.close();
	g.close();
	return 0;
}