Cod sursa(job #1357727)

Utilizator edigiorgiEdi Georgi edigiorgi Data 24 februarie 2015 02:43:48
Problema Convertor Scor 80
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.62 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);
				do
				{
					g << x;
					f.get(x);
				} while (x != '"');
				g << ',';

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

		}
		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 << ',';

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

				}
				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.get(c);
			}
			g << endl;
		}
		
	} while (f.get(c));
	f.close();
	g.close();
	return 0;
}