日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Tautology--POJ 3295

發布時間:2025/7/14 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Tautology--POJ 3295 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、題目類型:模擬題、棧、位運算。

2、解題思路:(1)題意只用到5個 bool 變量,所以用0—32的 int 型用于循環;(2)根據str的操作符性質不停的出戰、入棧直到循環結束。(3)判斷最終棧中數據的真假,輸出結果。

3、注意事項:從str.length()-1開始循環出入棧;

4、實現方法:

#include<iostream>
#include
<string>
#include
<stack>
using namespace std;

stack
<bool> sta;
bool val[5],flag;

int main()
{
int i,j;
string str;
bool tmp1,tmp2;
while(cin>>str && str!="0")
{
flag
=1;
for(i=0;i<32 && flag;i++)
{
memset(val,
0,sizeof(val));
for(j=0;j<5;j++)
{
if(i & (1<<j))
val[j]
=1;
}
for(j=str.length()-1;j>=0;j--)
{
switch(str[j])
{
case 'p':case 'q':case 'r':case 's':case 't':
sta.push(val[str[j]
-'p']);
break;
case 'N':
tmp1
=sta.top();
sta.pop();
sta.push(
!tmp1);
break;
case 'E':
tmp1
=sta.top();
sta.pop();
tmp2
=sta.top();
sta.pop();
sta.push(tmp1
==tmp2);
break;
case 'A':
tmp1
=sta.top();
sta.pop();
tmp2
=sta.top();
sta.pop();
sta.push(tmp1
||tmp2);
break;
case 'K':
tmp1
=sta.top();
sta.pop();
tmp2
=sta.top();
sta.pop();
sta.push(tmp1
&& tmp2);
break;
case 'C':
tmp1
=sta.top();
sta.pop();
tmp2
=sta.top();
sta.pop();
if(tmp2 && !tmp1)
tmp1
=0;
else
tmp1
=1;
sta.push(tmp1);
break;
default:
break;
};
}
if(!sta.top())
flag
=0;
}
if(flag)
cout
<<"tautology"<<endl;
else
cout
<<"not"<<endl;
}
return 0;
}

?

轉載于:https://www.cnblogs.com/yongze103/archive/2010/08/03/1791612.html

總結

以上是生活随笔為你收集整理的Tautology--POJ 3295的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。