Pagini recente » Cod sursa (job #3294154) | Cod sursa (job #2444691) | Cod sursa (job #3033491) | Cod sursa (job #1547916) | Cod sursa (job #1348821)
#include<fstream>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
class Convertor{
ifstream *in;
ofstream *out;
public:
Convertor(ifstream &in, ofstream &out);
void solve();
};
Convertor::Convertor(ifstream &in, ofstream &out){
this->in = ∈ this->out = &out;
}
void Convertor::solve(){
ifstream &f = *in;
ofstream &g = *out;
vector<string> firstValues;
f>>noskipws; //not to skip whitespaces
char c;
f>>c;
while(true){
while(c!='"'){
f>>c;
}
f>>c; //we're jumping over the '"'
while(c!='"'){
g<<c; //printing the mutual keys
f>>c;
}
g<<',';
f>>c;
while((c<'0' || c>'9') && c!='"'){
f>>c;
}
if(c=='"'){ //if we have a string
f>>c;
string firstElementString;
while(c!='"'){
firstElementString.append(1, c);
f>>c;
}
firstValues.push_back(firstElementString);
}
else{
string firstElementString;
while(c>='0' && c<='9'){
firstElementString.append(1, c);
f>>c;
}
firstValues.push_back(firstElementString);
}
while(c!=',' && c!='}'){
f>>c;
}
if(c=='}'){
g<<'\n';
break; //finished first object
}
}
for(int i=0; i<firstValues.size(); ++i){ //printing first values
g<<firstValues[i]<<',';
}
g<<'\n';
while(true){
f>>c;
while (c!= '{' && c != ']'){
f>>c;
}
if(c==']'){
break;
}
while(true){
f>>c;
while(c!=':'){
f>>c;
}
f>>c;
while((c<'0' || c>'9') && c!='"'){
f>>c;
}
if(c=='"'){
f>>c;
while(c!='"'){
g<<c;
f>>c;
}
g<<',';
}
else{
while(c>='0'&&c<='9'){
g<<c;
f>>c;
}
g<<',';
}
while(c!=',' && c!='}'){
f>>c;
}
if(c=='}'){
g<<'\n';
break;
}
}
}
}
int main(){
ifstream f("convertor.in");
ofstream g("convertor.out");
Convertor *newConvertor = new Convertor(f,g);
newConvertor->solve();
return 0;
}