Pagini recente » Cod sursa (job #1426211) | Cod sursa (job #635656) | Cod sursa (job #1355597) | Cod sursa (job #1688215) | Cod sursa (job #1357722)
#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)
{
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)
{
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;
}