Pagini recente » Cod sursa (job #936549) | oniprec | Cod sursa (job #2091153) | Cod sursa (job #1840012) | Cod sursa (job #1345570)
// CDL.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string expression = "";
string line = "";
ifstream inputFile("convertor.txt");
ofstream outputFile("convertor.out");
while (getline(inputFile, line)) {
expression += line;
}
vector <string> a,b,c,d,e;
string delimiters = "}";
size_t current;
size_t next = -1;
do
{
current = next + 1;
next = expression.find_first_of(delimiters, current);
a.push_back(expression.substr(current, next - current));
} while (next != string::npos);
expression = a[0];
int limit=0,k=0;
int length;
length = expression.size();
while (limit<length && limit!=-1) {
limit = expression.find_first_of(",");
if (limit != -1) {
k = 0;
c.push_back(expression.substr(k, limit));
k = limit;
expression = expression.substr(k+1, length - 1);
}
}
c.push_back(expression);
int ll = c.size();
for (int i = 0; i < ll; i++) {
int limit1 = 0, k1 = 0;
int length1 = c[i].size();
while (limit1<length1 && limit1 != -1) {
limit1 = c[i].find_first_of(":");
if (limit1 != -1 ) {
k1 = 0;
d.push_back(c[i].substr(k1, limit1));
k1 = limit1;
c[i] = c[i].substr(k1 + 1, length1 - 1);
}
}
outputFile << d[0].substr(d[0].find_first_of(34) + 1, d[0].find_last_of(34) - d[0].find_first_of(34) -1);
outputFile << ",";
d.clear();
}
outputFile << endl;
//pana aici e bine
for (int i = 0; i < a.size() - 1; i++) {
int limit2= 0, k2 = 0;
int length2 = a[i].size();
while (limit2<length2 && limit2 != -1) {
limit2 = a[i].find_first_of(",");
if (limit2 != -1) {
k2 = 0;
e.push_back(a[i].substr(k2, limit2));
k2 = limit2;
a[i] = a[i].substr(k2 + 1, length2 - 1);
}
}
e.push_back(a[i]);
int l = e.size();
for (int j = 0; j < l; j++) {
if ((i > 0 && j != 0) || (i == 0)) {
int limit3 = 0, k3 = 0;
int length3 = e[j].size();
while (limit3 < length3 && limit3 != -1) {
limit3 = e[j].find_first_of(":");
if (limit3 != -1) {
k3 = 0;
b.push_back(e[j].substr(k3, limit3));
k3 = limit3;
e[j] = e[j].substr(k3 + 1, length3 - 1);
}
}
b.push_back(e[j]);
string s2;
if (b[1].find_first_of(34) != -1) {
s2 = b[1].substr(b[1].find_first_of(34) + 1,
b[1].find_last_of(34) - b[1].find_first_of(34) -1);
}
else {
s2 = b[1];
size_t endpos = s2.find_last_not_of(" ");
if (string::npos != endpos)
{
s2= s2.substr(0, endpos + 1);
}
size_t startpos = s2.find_first_not_of(" ");
if (string::npos != startpos)
{
s2 = s2.substr(startpos);
}
}
outputFile<<s2;
outputFile<<",";
b.clear();
}
}
e.clear();
if (i != a.size() - 2) {
outputFile<<"\n";
}
}
inputFile.close();
outputFile.close();
//cout <<endl<< c[0] << endl << c[1];
return 0;
}