Cod sursa(job #1357396)
Utilizator | Data | 23 februarie 2015 21:55:08 | |
---|---|---|---|
Problema | Convertor | Scor | 10 |
Compilator | cpp | Status | done |
Runda | rosedu_cdl_2015 | Marime | 2.96 kb |
#include<iostream>
#include<fstream>
#include<cstring>
#include<vector>
#include<ctype.h>
using namespace std;
int main()
{
ifstream f("convertor.in");
ofstream g("convertor.out");
char a[1024],b[1024];
char tags[1024][1024];
int k,t=0,i,tagsCount=0;
while(t==0)
{
f.getline(a,1024);
if(strchr(a,'}'))
t=1;
i=0;
while(a[i]!='\0')
{
if(a[i]=='}')
break;
else
if(a[i]=='"')
{
int var=i;
i++;
while(a[i]!='"')
{
b[i-var-1]=a[i];
i++;
}
b[i-var-1]='\0';
strcpy(tags[tagsCount],b);
tagsCount++;
while(a[i]!=',')
{
i++;
if(a[i]=='}')
break;
}
}
else
i++;
}
}
for(i=0;i<tagsCount;i++)
g<<tags[i]<<",";
g<<"\n";
f.clear();
bool fin;
f.seekg(0,f.beg);
while(!f.eof())
{
f.getline(a,1024);
for(i=0;i<strlen(a);i++)
{
if(a[i]==']')
goto jump;
if(a[i]==','&&(a[i-1]=='"'||isdigit(a[i-1])||a[i-1]=='}'))
{
fin=false;
int var;
if(a[i-1]=='"')
{
var=i-1;
i=i-2;
while(a[i-1]!='"'&&i!=0)
i--;
}
if(isdigit(a[i-1]))
{
var=i;
i--;
while(isdigit(a[i-1]))
i--;
}
if(a[i-1]=='}')
{
jump:
i=i-2;
fin=true;
while(!isdigit(a[i])&&a[i]!='"')
i--;
if(isdigit(a[i]))
{
var=i;
while(isdigit(a[i-1]))
i--;
}
else
{
var=i;
i=i-1;
while(a[i-1]!='"'&&i!=0)
i--;
}
}
for(;i<var;i++)
g<<a[i];
i++;
g<<",";
if(fin==true)
{
g<<"\n";
i=i+3;
}
}
}
}
}