Cod sursa(job #397690)

Utilizator mottyMatei-Dan Epure motty Data 17 februarie 2010 12:40:44
Problema Bool Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<stdio.h>

bool AND(int i);
bool OR(int i);
bool NOT(int i);
bool FALSE(int i);
bool TRUE(int i);

void read()
{
	gets(c);
	int lim=strlen(c);
	for( int i=0 ; i<lim ; ++i )
		if( AND(i) )
		{
			v[poz++]='&';
			i+=2;
		}
		else if( OR(i) )
		{
			v[poz++]='|';
			i+=1;
		}
		else if( NOT(i) )
		{
			v[poz++]='!';
			i+=2;
		}
		else if( TRUE(i) )
		{
			v[poz++]='1';
			i+=3;
		}
		else if( FALSE(i) )
		{
			v[poz++]='0';
			i+=4;
		}
		else if( c[i]=' ');
		else
			v[poz++]=c[i];
}

int main()
{
	freopen("bool.in","r",stdin);
	freopen("bool.out","w",stdout);
	read();
	return 0;
}

void AND(int i)
{
	if( c[i]=='A'&&c[i+1]=='N'&&c[i+2]=='D')
		return 1;
	return 0;
}

void OR(int i)
{
	if( c[i]=='O' && c[i+1]=='R' )
		return 1;
	return 0;
}

void NOT(int i)
{
	if( c[i]=='N'&&c[i+1]=='O'&&c[i+2]=='T')
		return 1;
	return 0;
}

void FALSE(int i)
{
	if( c[i]=='F'&&c[i+1]=='A'&&c[i+2]=='L'&&c[i+3]=='S'&&c[i+4]=='E' )
		return 1;
	return 0;
}

void TRUE(int i)
{
	if( c[i]=='T'&&c[i+1]=='R'&&c[i+2]=='U'&&c[i+3]=='E')
		return 0;
	return 1;
}