Cod sursa(job #1347056)

Utilizator alex.bullzAlexandru Lilian alex.bullz Data 18 februarie 2015 19:25:49
Problema Convertor Scor 100
Compilator cpp Status done
Runda rosedu_cdl_2015 Marime 1.43 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cctype>

bool state (int num) {
	if (num % 2 == 0)
		return false;
	return true;
}

int main() {
	std::ofstream out;
	std::ifstream in;
	std::string str = "";
	char c;
	std::vector<std::string> vect;
	bool ok = false;
	in.open ("convertor.in");
	
	int count = 0;
	int gcount = 0;
	
	if (in.is_open()) {
		out.open ("convertor.out");

		while (in.get (c)) {
			if (c == '"') {
				++gcount;
				ok = state (gcount);
				continue; // patched - lua in considerare si ghilimelele
			}
			
			if (ok) {
				str.push_back (c);
				if (in.peek() == '"') {
//					vect[count].assign (str);
//					str = "";
//					++count;
					vect.push_back (str);
					str = "";
				}
				continue; // ???
			}

			if (isalnum (c) && ok == false) {
				str.push_back (c);
				if (!isalnum(in.peek())) {
//					vect[count].assign (str);
//					str = "";
//					++count;
					vect.push_back (str);
					str = "";
				}
			}
		}
	}

	in.close();

	std::string comp = vect[0];
	int no_obj = 1;
	out << vect[0] << ',';
	for (int i = 2; i < vect.size(); i += 2) {
		if (vect[i] == comp) {
			break;
		}

		no_obj++;
		out << vect[i] << ',';
	}
	out << '\n';
	
	std::cout << no_obj << std::endl;

	count = 0;
	for (int i = 1; i < vect.size(); i += 2) {
		++count;

		out << vect[i] << ',';

		if (count == no_obj) {
			count = 0;
			if (i == vect.size() - 1)
				break;
			out << "\n";
		}
	}

	out.close();

	return 0;
}