Cod sursa(job #1345656)

Utilizator paula.simaSima Paula paula.sima Data 17 februarie 2015 19:43:25
Problema Convertor Scor 70
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 2.89 kb
// 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 main(int argc, char* argv[])
{
	string expression = "";
	string line = "";
	ifstream inputFile("convertor.in");
	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];
	
	expression = expression.substr(0, expression.find_last_of(":"));
	expression = expression.substr(expression.find_first_of(34)+1, expression.find_last_of(34) - expression.find_first_of(34));
	
	while (expression.size() > 0 && expression.find_first_of(",")!=-1) {
		outputFile << expression.substr(0, expression.find_first_of(34));
		outputFile << ",";
		expression = expression.substr(expression.find_first_of(","));
		expression = expression.substr(expression.find_first_of(34) + 1, expression.find_last_of(34) - expression.find_first_of(34));
	}
	
	outputFile << expression.substr(0, expression.size() - 1);
	outputFile << ",";
	outputFile << endl;

	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();
	return 0;
}