Pagini recente » Cod sursa (job #1768582) | *PAGINA LUI VI$$U* | Rating Peace my pants (UPB_Darius_Rares_Silviu) | Borderou de evaluare (job #804585) | Cod sursa (job #1357538)
#include <fstream>
#include <vector>
using namespace std;
ifstream fin ("convertor.in");
ofstream fout ("convertor.out");
vector <string> Values;
int main() {
int op = 0;
/*
/ - 0, citesc cheie
/ - 1, citesc valoare
/
*/
bool keysFirst = true; // tratez cazul cand afisez prima linie
char c;
fin.get (c);
do {
if (c == '"') {
if (op == 0) {
// trebuie sa citesc o cheie
string key;
fin.get (c);
while (c != '"') {
key.push_back (c);
fin.get (c);
}
if (keysFirst)
fout << key << ",";
op = 1; // trebuie sa citesc valoare acum
fin.get (c);
} else {
// trebuie sa citesc o valoare
string value;
fin.get (c);
while (c != '"') {
value.push_back (c);
fin.get (c);
}
Values.push_back (value);
op = 0; // trebuie sa citesc cheie
fin.get (c);
}
} else if (c >= '0' && c <= '9') {
string value;
while (c >= '0' && c <= '9') {
value.push_back (c);
fin.get (c);
}
Values.push_back (value);
op = 0;
} else {
if (c == '}') {
if (keysFirst)
fout << '\n';
keysFirst = false;
for (int i = 0; i < Values.size(); i++)
fout << Values[i] << ',';
fout << '\n';
Values.clear();
}
fin.get (c);
}
} while (c != ']');
return 0;
}