Mai intai trebuie sa te autentifici.
Cod sursa(job #1347559)
Utilizator | Data | 19 februarie 2015 00:37:47 | |
---|---|---|---|
Problema | Convertor | Scor | 60 |
Compilator | cpp | Status | done |
Runda | rosedu_cdl_2015 | Marime | 1.26 kb |
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
string proc(string key)
{
while (key[0] == ' ' || key[0] == '"')
key.erase(key.begin(),key.begin()+1);
return key;
}
int main()
{
ifstream f("convertor.in");
ofstream g("convertor.out");
string key;
//vector <string> keys;
char p;
bool op = false;
int keys_nr = 0;
//caut cheile
while (p != '}' && f.peek() != EOF){
f.get(p);
if (p == '"' && !op){
op = true;
f.get(p);
}
if (p != '"' && op){
key.push_back(p);
}
if (p == '"' && op){
op=false;
g<<key<<",";
keys_nr++;
//keys.push_back(key);
key.clear();
while (p !=',' && p != '}' && f.peek() != EOF)
f.get(p);
}
}
//caut valorile;
g<<"\n";
f.seekg(0,f.beg);
key.clear();
int val_nr = 0;
while (f.peek() != EOF){
while (p != ':' && f.peek() != EOF){
f.get(p);
}
if (f.peek() == EOF)
break;
f.get(p);
while (p == ' ' || p == '"'){
f.get(p);
//cout<<"ceapa ";
//f.get(p);
}
while (p != '"' && p != ',' && p != '}'){
key.push_back(p);
f.get(p);
}
//cout<<key<<"\n";
fflush(stdout);
cout<<val_nr<<"\n";
if (val_nr == keys_nr)
g<<"\n",val_nr = 0;
g<<key<<",";
key.clear();
val_nr++;
}
g.close();
return 0;
}