POJ 3295 Tautologyシミュレーション
1673 ワード
題意:文字列が本物かどうかを判断する.
Definitions of K, A, N, C, and E
w x
Kwx
Awx
Nw
Cwx
Ewx
1 1
1
1
0
1
1
1 0
0
1
0
0
0
0 1
0
1
1
1
0
0 0
0
0
1
1
1
題解:p,q,r,s,tのブール値を列挙し,整数で表す.
Definitions of K, A, N, C, and E
w x
Kwx
Awx
Nw
Cwx
Ewx
1 1
1
1
0
1
1
1 0
0
1
0
0
0
0 1
0
1
1
1
0
0 0
0
0
1
1
1
題解:p,q,r,s,tのブール値を列挙し,整数で表す.
#include <iostream>
using namespace std;
int Nth_Char;
char str[101];
bool step ( char str[101], int logicValue )
{
Nth_Char++;
switch ( str[Nth_Char] )
{
case 'p': return logicValue & 1;
case 'q': return ( logicValue >> 1 ) & 1;
case 'r': return ( logicValue >> 2 ) & 1;
case 's': return ( logicValue >> 3 ) & 1;
case 't': return ( logicValue >> 4 ) & 1;
case 'N': return !step ( str, logicValue );
case 'K': return step ( str, logicValue ) & step ( str, logicValue );
case 'A': return step ( str, logicValue ) | step ( str, logicValue );
case 'C': return !step (str, logicValue ) | step ( str, logicValue );
case 'E': return step ( str, logicValue ) == step ( str, logicValue );
default:;
}
}
bool judge ( char str[101] )
{
for ( int i = 0; i < 32; i++ ) /* p,q,r,s,t */
{
Nth_Char = -1;
if ( !step ( str, i ) )
return false;
}
return true;
}
int main()
{
while ( cin >> str && str[0] != '0' )
{
if ( judge ( str ) )
cout << "tautology" << endl;
else
cout << "not" << endl;
}
return 0;PO
}