Pagini recente » Cod sursa (job #1038312) | Cod sursa (job #2894007) | Cod sursa (job #2372349) | Cod sursa (job #1107459) | Cod sursa (job #1338463)
#include <fstream>
#include <vector>
#include <string>
#include <stdio.h>
#include <cstring>
using namespace std;
ifstream cin("convertor.in");
ofstream cout("convertor.out");
vector<string> values;
char filling[] = ",: \n\"{}[]";
bool ignoreFilling() {
char c;
c = cin.get();
while(strchr(filling, c)) {
if(c == ']' || c == '}')
return false;
c = cin.get();
}
cin.unget();
return true;
}
string readWord() {
string word;
char c;
cin.unget();
c = cin.get();
if(c == '"') {
c = cin.get();
while(c != '"') {
word += c;
c = cin.get();
}
} else {
c = cin.get();
while(!strchr(filling, c)) {
word += c;
c = cin.get();
}
}
cin.unget();
return word;
}
bool readPair(int nr) {
if(!ignoreFilling())
return false;
string key = readWord();
if(nr == 1)
cout << key << ",";
ignoreFilling();
string value = readWord();
values.push_back(value);
return true;
}
bool readObj(int nr) {
if(!ignoreFilling())
return false;
bool thereArePairs = true;
while(thereArePairs)
thereArePairs = readPair(nr);
if(nr == 1)
cout << '\n';
for(int i = 0; i < values.size(); i++)
cout << values[i] << ",";
values.erase(values.begin(), values.end());
cout << '\n';
return true;
}
int main() {
int nr = 1;
bool thereAreObjects = true;
while(thereAreObjects)
thereAreObjects = readObj(nr++);
return 0;
}