Cod sursa(job #1343152)

Utilizator denisa.sanduDenisa Sandu denisa.sandu Data 14 februarie 2015 22:33:11
Problema Convertor Scor 70
Compilator c Status done
Runda rosedu_cdl_2015 Marime 1.25 kb
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int v[20000];
int main()
{
	char c;
	int ok=0, print=0, k=0, i=0, n;
	FILE *f, *out;
	f = fopen("convertor.in","rt");
	out = fopen("convertor.out","wt");
	while (fread(&c,1,1,f) && c!='}')
	{
		if (c == ',' || c == '[') {
			ok = 1;
			continue;
		}
		else if (c == ':') {
			ok = 0;
			continue;
		}
		if (ok) {
			if (c == '"' && print==0)
			{
				print = 1;
				continue;
			}
			else if (c == '"')
			{
				print = 0;
				k++;
				fprintf(out,",");
			}
		}
		if (print){
			v[k]++;
			fprintf(out,"%c", c);
		}

	}
	fseek(f, 0, SEEK_SET);
	ok = 0;
	fprintf(out,"\n");
	while (!feof(f))
	{
		fread(&c,1,1,f);;
		if (c == ':' ) {
			ok = 1;
			continue;
		}
		else if (c == ',' || c == ']') {
			ok = 0;
			continue;
		}
		if (ok) {
			if (c == '"' && print==0)
			{
				print = 1;
				continue;
			}
			else if (c == '"')
			{
				print = 0;
				fprintf(out,",");
				i++;
				if (i==k)
				{
					fseek(f,v[i],SEEK_CUR);
					i=0;
					fprintf(out,"\n");
				}

			}
		}
		if (print)
			fprintf(out,"%c", c);
		else if (!print && c>='0' && c<='9')
		{
			fseek(f,-1,SEEK_CUR);
			fscanf(f,"%d",&n);
			i++;
			
			fprintf(out,"%d,",n);
				if (i==k)
				{
					i=0;
					fprintf(out,"\n");
				}

		}
	}
	return 0;
}