Pagini recente » Cod sursa (job #1284549) | Cod sursa (job #2048543) | Statistici petruta (andrei_petruta) | Cod sursa (job #428824) | Cod sursa (job #1355175)
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
string keyArray, valueArray;
ifstream f("convertor.in");
string::size_type cIndex, left, right;
int objectCount = 0;
bool key = false;
while (getline(f, line))
{
do
{
if (!key)
{
cIndex = line.find_first_of("}\"");
if (cIndex != string::npos)
{
if (line[cIndex] == '}')
{
objectCount++;
left = cIndex;
right = left;
valueArray += '\n';
}
else
{
left = cIndex;
right = line.find("\"", cIndex + 1);
if (!objectCount)
keyArray += line.substr(left + 1, right - left - 1) + ",";
key = true;
}
cIndex = right + 1;
line = line.substr(cIndex);
}
}
else
{
cIndex = line.find_first_of("0123456789\"");
if (cIndex != string::npos)
{
if (line[cIndex] >= '0' && line[cIndex] <= '9')
{
left = cIndex;
right = line.find_first_not_of("0123456789", left + 1);
valueArray += line.substr(left, right - left) + ",";
cIndex = right + 1;
key = false;
}
else
{
left = cIndex;
right = line.find("\"", cIndex + 1);
valueArray += line.substr(left + 1, right - left - 1) + ",";
key = false;
cIndex = right + 1;
}
line = line.substr(cIndex);
}
}
} while (cIndex != string::npos);
}
f.close();
ofstream g("convertor.out");
g << keyArray << "\n" << valueArray;
g.close();
return 0;
}