Cod sursa(job #1344348)
Utilizator | Data | 16 februarie 2015 17:39:31 | |
---|---|---|---|
Problema | Convertor | Scor | 100 |
Compilator | cpp | Status | done |
Runda | rosedu_cdl_2015 | Marime | 2.75 kb |
#include<stdio.h>
#include<fstream>
#include <string>
using namespace std;
std::ofstream g;
int stare = 1;
int main()
{
int i;
std::string line;
std::ifstream f;
f.open("convertor.in");
g.open("convertor.out");
while(stare != 5 && getline(f, line) )
for(i=0; line[i]!='\0' && stare != 5; ++i){
char c = line[i];
switch(stare)
{
case 1:
if (c == '"') stare = 2;
break;
case 2:
if (c == '"')
{
stare = 3;
g<<',';
}
else
g<<c;
break;
case 3:
if (c == ',') stare = 4;
else if(c == '}') stare = 5;
break;
case 4:
if (c == '"') stare = 2;
break;
}
}
f.seekg (0, f.beg);
g<<"\n";
if(stare == 5)
{
stare = 1;
while( getline(f, line) )
for(i=0; line[i]!='\0'; ++i){
char c = line[i];
switch(stare)
{
case 1:
if (c == '"') stare = 2;
break;
case 2:
if (c == '"') stare = 3;
break;
case 3:
if (c == '"') stare = 4;
else if(c >='0' && c<='9')
{
g<<c;
stare = 5;
}
break;
case 4:
if (c == '"')
{
g<<",";
stare = 6;
}
else g<<c;
break;
case 5:
if (c == '"')
{
g<<",";
stare = 2;
}
else if ( c == '}')
{
g<<",";
stare = 7;
}
else if(c >='0' && c<='9') g<<c;
break;
case 6:
if (c == '"') stare = 2;
else if ( c == '}') stare = 7;
break;
case 7:
if (c == '{')
{
g<<"\n";
stare = 1;
}
break;
}
}
}
f.close();
g.close();
return 0;
}