| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
大牛帮我调试下程序, 不胜感激#include <iostream>
#include <stack>
#include <map>
using namespace std;
char str[100];
map<char , int> m;
bool cal(char * str, int a)
{
//return true;
stack<char> s;
int index = 0;
char tobe = str[index];
s.push(tobe);
index++;
tobe = str[index];
while (!s.empty())
{
if (m[tobe] == -1)
{
s.push(tobe);
index++;
tobe = str[index];
}
else
{
char tmp = s.top();
if (tmp == 'N')
{
s.pop();
if (m[tobe] >= 0)
{
if (1 << m[tobe] & a) tobe = '0';
else tobe = '1';
}
else
{
if (tobe == '0') tobe = '1';
else tobe = '0';
}
}
else if (tmp == '1' || tmp == '0')
{
s.pop();
char tmp1 = s.top();
s.pop();
switch (tmp1)
{
case 'K':
if (m[tobe] >= 0)
{
if ((1 << m[tobe] & a) && tmp == '1') tobe = '1';
else tobe = '0';
}
else
{
if (tobe == '1' && tmp == '1') tobe = 1;
else tobe = '0';
}
break;
case 'A':
if (m[tobe] >= 0)
{
if (1 << m[tobe] & a == 0 && tmp == '0') tobe = '0';
else tobe = '1';
}
else
{
if (tobe == '0' && tmp == '0') tobe = '0';
else tobe = '1';
}
break;
case 'C':
if (m[tobe] >= 0)
{
if ( (1 & (a >> m[tobe])) - (tmp - '0') >= 0 ) tobe = '1';
else tobe = '0';
}
else
{
if (tobe - tmp >= 0) tobe = '1';
else tobe = '0';
}
break;
case 'E':
if (m[tobe] >= 0)
{
if ( (1 & (a >> m[tobe])) != (tmp - '0') ) tobe = '0';
else tobe = '1';
}
else
{
if (tobe != tmp) tobe = '0';
else tobe = '1';
}
}
}
else
{
if (m[tobe] >= 0) s.push((1 & (a >> m[tobe])) + '0');
else s.push(tobe);
index++;
tobe = str[index];
}
}
}
if (tobe == '0') return false;
return true;
}
int main()
{
//freopen("in.txt", "r", stdin);freopen("out.txt", "w",stdout);
//int f;
// printf("%d\n", 0x001f);
m['p'] = 0;
m['q'] = 1;
m['r'] = 2;
m['s'] = 3;
m['t'] = 4;
m['K'] = -1;
m['A'] = -1;
m['N'] = -1;
m['C'] = -1;
m['E'] = -1;
m['0'] = -2;
m['1'] = -2;
//printf("%d\n", m['t']);
while (1)
{
gets(str);
if (str[0] == '0') break;
int flag = 1;
for (int i = 0; i <= 0x001f; i++)
{
if (cal(str, i) == false)
{
printf("%d\n", i);
flag = 0;
break;
}
}
if (flag) printf("tautology\n");
else printf("not\n");
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator