Cod sursa(job #1345716)

Utilizator paula.simaSima Paula paula.sima Data 17 februarie 2015 20:29:50
Problema Convertor Scor 50
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 2.23 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,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;
	string sss = "";
	for (int i = 0; i < a.size() - 1; i++) {
		
		while (a[i].size()>0 && a[i].find_first_of(":")!=-1) {

			a[i] = a[i].substr(a[i].find_first_of(":"));
			if (a[i].substr(0, a[i].find_first_of(",")).find_first_of(34) != -1) {
				sss = a[i].substr(0, a[i].find_first_of(","));
				
				outputFile << sss.substr(sss.find_first_of(34)+1, sss.find_last_of(34) - sss.find_first_of(34)-1);
				outputFile << ",";
				a[i] = a[i].substr(sss.find_last_of(34) + 1);
				
			}
			else {
				sss = a[i].substr(1, a[i].find_first_of(","));
				sss = sss.substr(0, sss.find_last_not_of(" "));
				sss = sss.substr(sss.find_first_not_of(" "));
				outputFile << sss << ",";
				a[i] = a[i].substr(a[i].find_first_of(",") + 1);
			}
		}
		outputFile << endl;
		
				
	}
	inputFile.close();
	outputFile.close();
	return 0;
}