Cod sursa(job #60434)

Utilizator anna_bozianuBozianu Ana anna_bozianu Data 14 mai 2007 14:02:59
Problema Bool Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.72 kb
#include<stdio.h>
#include<string.h>
char *expr,*val,*aux,c;
int l,l1,i,n,j,lv;
int main()
{
	FILE *f,*g;
	f=fopen("bool.in","r");
	g=fopen("bool.out","w");
	expr=new char [1000];
	aux=new char [1000];
	val=new char [1000];
	fgets(expr,1000,f);
	l=strlen(expr);
	aux=strstr(expr,"TRUE");
	while(aux)
	{ l1=strlen(aux);
	  for(i=1;i<=3;i++)aux++;
	  aux[0]='1';
	  strcpy(expr+l-l1,aux);
	  l=strlen(expr);
	  aux=strstr(expr,"TRUE");
	}
	aux=strstr(expr,"FALSE");
	while(aux)
	{ l1=strlen(aux);
	  for(i=1;i<=4;i++)aux++;
	  aux[0]='0';
	  strcpy(expr+l-l1,aux);
	  l=strlen(expr);
	  aux=strstr(expr,"FALSE");
	}
	aux=strstr(expr,"OR");
	while(aux)
	{ l1=strlen(aux);
	  for(i=1;i<=1;i++)aux++;
	  aux[0]='+';
	  strcpy(expr+l-l1,aux);
	  l=strlen(expr);
	  aux=strstr(expr,"OR");
	}
	aux=strstr(expr,"AND");
	while(aux)
	{ l1=strlen(aux);
	  for(i=1;i<=2;i++)aux++;
	  aux[0]='*';
	  strcpy(expr+l-l1,aux);
	  l=strlen(expr);
	  aux=strstr(expr,"AND");
	}
	aux=strstr(expr,"NOT");
	while(aux)
	{ l1=strlen(aux);
	  for(i=1;i<=2;i++)aux++;
	  aux[0]='~';
	  strcpy(expr+l-l1,aux);
	  l=strlen(expr);
	  aux=strstr(expr,"NOT");
	}
	aux=strstr(expr," ");
	while(aux)
	{ l1=strlen(aux);
	  aux++;
	  strcpy(expr+l-l1,aux);
	  l=strlen(expr);
	  aux=strstr(expr," ");
	}
        strcpy(val,expr);
	fscanf(f,"%d",&n);
	fscanf(f,"%c",&c);
	for(j=1;j<=n;j++)
	{
		fscanf(f,"%c",&c);
		for(i=0;i<=l;i++)
		{ if(expr[i]==c) expr[i]=c-'A'+'a';
		  else
		   if(expr[i]==c-'A'+'a')expr[i]=c;
		}
		for(i=0;i<=l;i++)
		{ if(('a'<=expr[i])&&('z'>=expr[i]))val[i]='1';
		  else
		  if(('A'<=expr[i])&&('Z'>=expr[i]))val[i]='0';
		}
		lv=l;

	}
	fprintf(g,"\n");
	fcloseall();
	return 0;
}