Pagini recente » Rating Tomescu Alexandru (Tomytza) | Cod sursa (job #514808) | Cod sursa (job #1299658) | Cod sursa (job #2590488) | Cod sursa (job #1354644)
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
string keyArray, valueArray, currentSubString;
ifstream f("convertor.in");
string::size_type iIndex, cIndex, left, right;
int objectCount = 0;
while (getline(f, line))
{
iIndex = 0;
cIndex = line.find_first_of(":}");
while (cIndex != string::npos)
{
if (line[cIndex] == ':')
{
if (!objectCount)
{
currentSubString = line.substr(iIndex, cIndex - iIndex + 1);
left = currentSubString.find("\"");
right = currentSubString.rfind("\"");
keyArray += line.substr(left + 1, right - left - 1) + ",";
}
left = line.find_first_of("0123456789\"", cIndex + 1);
if (line[left] >= '0' && line[left] <= '9')
{
right = line.find(",", left + 1);
valueArray += line.substr(left, right - left) + ",";
}
else
{
right = line.find("\"", left + 1);
valueArray += line.substr(left + 1, right - left - 1) + ",";
}
cIndex = right;
}
else if (line[cIndex] == '}' && line[cIndex + 1] == ',')
{
if (!objectCount)
keyArray += '\n';
valueArray += '\n';
objectCount++;
}
line = line.substr(cIndex + 1, line.size() - cIndex + 1);
cIndex = line.find_first_of(":}");
}
}
f.close();
ofstream g("convertor.out");
g << keyArray << valueArray;
g.close();
return 0;
}