{"id":714,"date":"2020-04-09T20:05:15","date_gmt":"2020-04-09T12:05:15","guid":{"rendered":"http:\/\/kylelv.com\/?p=714"},"modified":"2020-04-09T20:05:15","modified_gmt":"2020-04-09T12:05:15","slug":"boolean-expressions-%e9%80%92%e5%bd%92","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=714","title":{"rendered":"Boolean Expressions &#8212; \u9012\u5f52"},"content":{"rendered":"\n<h2 class=\"has-text-align-center wp-block-heading\">A:Boolean Expressions<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:\u00a01000ms\u00a0\u5185\u5b58\u9650\u5236:\u00a065536kB<\/p>\n\n\n\n<p>\u63cf\u8ff0<\/p>\n\n\n\n<p>The objective of the program you are going to produce is to evaluate boolean expressions as the one shown next:<br>Expression: ( V | V ) &amp; F &amp; ( F | V )<br>where V is for True, and F is for False. The expressions may include the following operators: ! for not , &amp; for and, | for or , the use of parenthesis for operations grouping is also allowed.<\/p>\n\n\n\n<p>To perform the evaluation of an expression, it will be considered the priority of the operators, the not having the highest, and the or the lowest. The program must yield V or F , as the result for each expression in the input file.<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>The expressions are of a variable length, although will never exceed 100 symbols. Symbols may be separated by any number of spaces or no spaces at all, therefore, the total length of an expression, as a number of characters, is unknown.<\/p>\n\n\n\n<p>The number of expressions in the input file is variable and will never be greater than 20. Each expression is presented in a new line, as shown below.<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>For each test expression, print &#8220;Expression &#8221; followed by its sequence number, &#8220;: &#8220;, and the resulting value of the corresponding test expression. Separate the output for consecutive test expressions with a new line.<\/p>\n\n\n\n<p>Use the same format as that shown in the sample output shown below.<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">( V | V ) &amp; F &amp; ( F| V)\n!V | V &amp; V &amp; !F &amp; (F | V ) &amp; (!F | F | !V &amp; V)\n(F&amp;F|V|!V&amp;!F&amp;!(F|F&amp;V))<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Expression 1: F\nExpression 2: V\nExpression 3: V<\/pre>\n\n\n\n<p>\u6765\u6e90M\u00e9xico and Central America 2004<\/p>\n\n\n\n<p>\u672c\u6765\u60f3\u7c98\u4e00\u53d1\u4ee3\u7801\uff0c\u7ed3\u679c\u53d1\u73b0\u7f51\u4e0a\u7684\u53c8\u957f\u53c8\u4e11\uff08\u9003\uff0c\u5c31\u81ea\u5df1\u5199\u4e86\u4e0b<br>\u5c31\u662f\u4e00\u4e2a\u7b80\u5355\u9012\u5f52\uff0c\u8bb0\u5f55\u51e0\u4e2a\u53d8\u91cf\uff0c\u5339\u914d\u4e00\u4e0b\u62ec\u53f7\uff08\u7136\u540e\u6211\u90fd\u76f4\u63a5\u7528\u7684\u5168\u5c40\u53d8\u91cf\u9012\u5f52qaq<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;iostream>\nusing namespace std;\n#define N 220\nchar s&#91;N];\nint n,T,x;\nbool mk(bool a,bool b,bool op){\n    if(op) return a&amp;b;\n    else return a|b;\n}\nbool get(){\n    bool tp=0,nf=0,op=0;\n    while(x&lt;n){\n        if(s&#91;x]=='!') nf=1,++x;\n        else if(s&#91;x]=='(') ++x,tp=mk(tp,get()^nf,op),nf=op=0;\n        else if(s&#91;x]==')'){++x;return tp;}\n        else if(s&#91;x]=='|') op=0,++x;\n        else if(s&#91;x]=='&amp;') op=1,++x;\n        else if(s&#91;x]=='V') tp=mk(tp,1^nf,op),nf=op=0,++x;\n        else if(s&#91;x]=='F') tp=mk(tp,0^nf,op),nf=op=0,++x;\n        else ++x;\n    }\n    return tp;\n}\nint main()\n{\n    while(cin.getline(s,200)){\n        n=strlen(s);++T;x=0;\n        printf(\"Expression %d: %c\\n\",T,get()?'V':'F');\n    }\n    return 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A:Boolean Expressions \u603b\u65f6\u95f4\u9650\u5236:\u00a01000ms\u00a0\u5185\u5b58\u9650\u5236:\u00a065536kB \u63cf\u8ff0 Th [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[76],"class_list":["post-714","post","type-post","status-publish","format-standard","hentry","category-70","tag-76"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=714"}],"version-history":[{"count":1,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/714\/revisions"}],"predecessor-version":[{"id":715,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/714\/revisions\/715"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}