Pagini recente » Cod sursa (job #1464041) | Cod sursa (job #304770) | Cod sursa (job #2012970) | Cod sursa (job #1703356) | Cod sursa (job #1347056)
#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;
}