Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴代码

Posted by dw_tanshunwen at 2012-11-29 01:43:32 on Problem 3295
#include <stdio.h>
#include <string.h>

char data[124];
int paras[124];

bool inputData()
{
	scanf("%s", &data);
	return (strcmp(data, "0") != 0);
}

bool getValue(int values[])
{
	int len = strlen(data);
	int pl = 0;
	for (int i = len - 1; i >= 0; -- i)
	{
		if (data[i] >= 'p' && data[i] <= 't')
		{
			paras[pl] = values[data[i] - 'p'];
			++ pl;
		}
		else if (data[i] == 'K')
		{
			paras[pl - 2] = (paras[pl - 2] & paras[pl - 1]);
			-- pl;
		}
		else if (data[i] == 'A')
		{
			paras[pl - 2] = (paras[pl - 2] | paras[pl - 1]);
			-- pl;
		}
		else if (data[i] == 'N')
		{
			paras[pl - 1] = 1 - paras[pl - 1];
		}
		else if (data[i] == 'C')
		{
			paras[pl - 2] = ((paras[pl - 1] ^ 1) | paras[pl - 2]);
			-- pl;
		}
		else if (data[i] == 'E')
		{
			paras[pl - 2] = 1 - (paras[pl - 1] ^ paras[pl - 2]);
			-- pl;
		}
	}

	return (paras[0] == 1);
}

void process()
{
	bool ret = true;
	int values[5];
	for (int i = 0; i < 32; ++ i)
	{
		for (int j = 0; j < 5; ++ j)
		{
			values[j] = (i & (1 << j)) ? 1 : 0;
		}

		ret &= getValue(values);

		if (!ret)
		{
			break;
		}
	}

	if (ret)
	{
		printf("tautology\n");
	}
	else
	{
		printf("not\n");
	}
}

int main()
{
	while (inputData())
	{
		process();
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator